Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Hi everyone again im back with more questions about Bash scripts
so i have my bash script and i have an if statement followed by elif statement and i would like to put an if statement inbetween the other if statements but if i do then it gives me an error saying somthing is wrong at the end of the script can you please help me thank you !
Can you post your script, and the error output your receive? That will help us assist you.
You probably just need to sort out the nesting of your "if" statements and close them in the correct order.
Regards,
R.
Yes i will ! here you go !
Code:
#/bin/bash
# Init
FILE="/tmp/out.$$"
GREP="/bin/grep"
#....
# Make sure only root can run our script
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root Type su into your terminal and enter your password and try to run this script again" 1>&2
exit 1
fi
function welcome {
clear
mkdir /mnt/usbflash/
#read -p command asks for user input on what to do
read -p "Hello, "$USER". would you like to restore or backup your home directory? Enter restore or backup and press [ENTER] : "
echo
echo
echo
read -p "Please Specify which user's home directory you would like to Backup/restore and press [ENTER] : " THUSER
echo
echo
echo
# if [ "$REPLY"] statements are to tell what to do with the user input
if [ "$REPLY" == "backup" ]; then
#read -p "Would you like to backup to an external drive or store the backup on your harddrive? for external drive type ed for harddrive type hdd and press [ENTER] : " WHERE
read -p "Please specify what you would like the backup to be called then press [ENTER] : " BACKUP
read -p "Would you like to back up to a external drive or your harddrive? for external drive type ed for harddrive type hdd and press [ENTER] : " WHERE
read -p "please specify which directory you would like backed up example /home/"$USER"/ : " DIR
if [ "$WHERE" == "ed" ]; then
sudo umount /dev/sdb
read -p "Would you like to format your flashdrive ? (y/N) : " FORMAT
[ "$FORMAT" == "y" ]
sudo mkfs.vfat -n Backup -I /dev/sdb
echo "Format complete"
cd /mnt/usbflash
sudo mount /dev/sdb/ /mnt/usbflash
cd /mnt/usbflash/
sudo tar -cf - "$DIR" | gzip -c > /mnt/usbflash/"$BACKUP".tar.gz
echo "Your backup is complete"
exit
["$FORMAT" == "n"]
cd /mnt/usbflash
sudo mount /dev/sdb/ /mnt/usbflash/
cd /mnt/usbflash
sudo tar -cf - "$DIR" | gzip -c > /mnt/usbflash/"$BACKUP".tar.gz
echo "Your backup is complete."
elif [ "$WHERE" == "hdd" ]; then
sudo tar -cf - "$DIR" | gzip -c > /mnt/usbflash/"$BACKUP".tar.gz
echo "Your backup is complete
elif [ "$REPLY" == "restore" ]; then
read -p "Warning this will overwrite the selected directory with the files in this backup do you want to continue? (y/n) : " CONTINUE
[ "$CONTINUE" == "y" ]
cd /mnt/usbflash
find -type f -name \*.tar.gz
read -p "type the name of your file without the .tar.gz extension and press [ENTER]"
sudo tar xvpfz "$RESTORENAME".tar.gz -C /home/"$THUSER"/
exit
[ "$CONTINUE" == "n" ]
exit
else
echo "Your selection was invalid. Please try again. Valid responses are: 'backup' and 'restore'."
welcome
fi
}
welcome
what im trying to do is add more options between the if [ "$REPLY" ] statement or somthing that will work out the same
and my error
Code:
root@huntaz-ThinkPad-R61i:/home/huntaz# back
/home/huntaz/script.sh: line 53: syntax error near unexpected token `('
/home/huntaz/script.sh: line 53: ` read -p "Warning this will overwrite the selected directory with the files in this backup do you want to continue? (y/n) : " CONTINUE'
there it is saying one of the read -p's is wrong..
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.