This is my first shell script, so I am trying to see if I can get some suggestions. It extracts saved wifi passwords from Linux.
##################################################################
# This script is used to copy wifi password files from /etc/NetworkManager/system-connections folder
# check if the wifi_pass_dir exists, and delete it if it does
if [ -d "wifi_pass_dir" ]
then
rm -rf wifi_pass_dir
fi
# Create wifi_pass_dir folder
mkdir wifi_pass_dir
#copy the files from NetworkManager to the folder created, these files can only be read by the root user so use sudo
sudo cp /etc/NetworkManager/system-connections/* ./wifi_pass_dir
# change the file permission from read only by root to read and write by any user (666)
sudo chmod 666 ./wifi_pass_dir/*
#create a list so we know what wifi passwords are saved
sudo ls /etc/NetworkManager/system-connections > ./wifi_pass_dir/pass_list.txt
# Read name of wifi from pass_list.txt and print on screen
cd wifi_pass_dir
filename="pass_list.txt"
while read -r line
do
name="$line"
echo $name
cat "$name" | grep psk=
done < "$filename"
##################################################################