1
Hey I'm running my shell script that interacts with folders and files, but my $PWD that it keeps pointing to /home/MyUserName directory and this messes with what it is supposed to do. I am running Linux 4.4.8-300.fc23.x86_64 GNU/Linux:
#!/usr/bin/bash -x
clear
ls $PWD
#Check Root
echo checking Root user
if [ $EUID -ne 0 ]
then
sudo su
fi;
#Check internet availablity
TEST=$(ping -c 1 74.125.21.14|wc -l)
if [ $TEST -gt 5 2>&1 ]
then
sudo dnf install gcc kernel-devel binutils cpp glibc-devel glibc-headers isl kernel kernel-headers libmpc
else
echo "No Internet Connection Available! Installing RPMs manuely."
arr=(*.rpm)
for (( i=0; i<${#arr[@]}; i++ ));
do
echo " ${arr[$i]} "
dnf -y install ${arr[$i]}
done
fi;
# Get Network Ability
echo "Starting the setup of your laptop's wireless card."
if [ -d ./MyWirelessCard ]
then
FILE=./MyWirelessCard/fedora23_broadcom_wl_install.sh
uname1=" $( stat -c "%u" $FILE ) "
[ " $USERNAME1 = 1000" ] || chown 1000 $FILE
[ " -r -w -x $FILE " ] || chmod +rwx $FILE
else
mkdir ./MyWirelessCard
FILE=./MyWirelessCard/fedora23_broadcom_wl_install.sh
uname1=" $( stat -c "%u" $FILE ) "
[ " $USERNAME1 = 1000" ] || chown 1000 $FILE
[ " -r -w -x $FILE " ] || chmod +rwx $FILE
fi;
#Making wireless card installer run on boot
#echo "Making the wireless card install script run on boot"
#ln -s ./MyWirelessCard/fedora23_broadcom_wl_update.sh /etc/init.d/
#ln -s ./MyWirelessCard/fedora23_broadcom_wl_update.sh /etc/rc.d/
# Initial Update
echo "Preforming initial system update."
dnf -y update
#Exit
echo Script is finished
exit
I get:
- ls /home/MyUserName Contents Of Folder
- echo checking Root user checking Root user
- '[' 1000 -ne 0 ']'
- sudo su [sudo] password for MyUserName: ++ ping -c 1 74.125.21.14 ++ wc -l
- TEST=6
- '[' 6 -gt 5 ']'
- sudo dnf install gcc kernel-devel binutils cpp glibc-devel glibc-headers isl kernel kernel-headers libmpc [sudo] password for dcarr:
- echo 'Starting the setup of your laptop'\''s wireless card.' Starting the setup of your laptop's wireless card.
- '[' -d ./MyWirelessCard ']'
- mkdir ./MyWirelessCard
- FILE=./MyWirelessCard/fedora23_broadcom_wl_install.sh ++ stat -c %u ./MyWirelessCard/fedora23_broadcom_wl_install.sh stat: cannot stat ‘./MyWirelessCard/fedora23_broadcom_wl_install.sh’: No such file or directory
- uname1=' '
- '[' ' = 1000' ']'
- '[' ' -r -w -x ./MyWirelessCard/fedora23_broadcom_wl_install.sh ' ']'
- echo 'Preforming initial system update.' Preforming initial system update.
- dnf -y update Error: This command has to be run under the root user.
- echo Script is finished Script is finished
- exit
I am at a loss any help would be greatly appreciated.
Unless I'm missing something, the
sudo su
stuff is pointless. It's probably not good practice anyway, it's enough to complain about not running as root and exit. /edit: Ah, you're relying on authentication caching. That's even worse. :D – Daniel B – 2016-05-02T21:06:01.200Related reading – Daniel B – 2016-05-02T21:11:29.720
Your quoting is wrong in many places. For example
[ " -r -w -x $FILE " ]
needs to be[ -r "$FILE" ] && [ -w "$FILE" ] && [ -x "$FILE" ]
-- your code will never be "false" – glenn jackman – 2016-05-02T21:23:03.107If you have to create that directory, then the $FILE will certainly not exist. – glenn jackman – 2016-05-02T21:26:21.780
Interesting, but just out of curiosity, what is the difference? It does it's job for me, at least as far as I know – Purpe_Fedora – 2016-05-02T21:26:38.830