Bash user input
Okay i have a script thats doing a simple backup but i need user input and im baffled on how im doing this..
heres what i have right now Code:
#/bin/bash |
Check your syntax for read. You need to specify a variable to save the user input to. Try something like this:
read -p "your message to user here: " REPLY |
hmm that didnt really help.. because there is a certain way the two replys need to be seperated i just dont know how.
|
It appears you are using || instead of && after the short hand if statement.
I would rewrite things a bit. Rather than chaining commands together, it would be easier to read and write, in my opinion, to do it more like this: Code:
#!/bin/bash |
Quote:
so what happens is i do the backup option and what i get is this Code:
Hello, huntaz. would you like to restore or backup your home directory? Enter restore or backup and press [ENTER] : backup thanks again ! |
Yeah that's because the tar file is being written to the same path that you are backing up. A better idea would be to temporarily store the backup somewhere else like in /home or /var/backup or something like that. Once the tar is done then you can move the .tar.gz file back over to the wanted directory.
|
I would like to add a few observations:
1. REPLY is the default variable used by read when no variable is supplied. So there is no need to include it (I would use an alternate variable name if you do wish to add one) 2. You need to be careful when using multiple || and && tests. Sometimes you can get unexpected results if you think it will just exit after getting first error. 3. When performing multiple tasks it is often clearer to use an if construct as provided by countach74 4. Newer versions of tar allow you to simply use the 'a' switch which will select the correct compression based on the file name: Code:
tar acf /home/$USER/backup.tar.gz . |
Ahh, I didn't realize REPLY was the default variable name. Thanks for the input, grail.
|
Personally I find the case command less cluttered and more transparent for this type of thing
Code:
function welcome { |
Thank you guys so much you have helped me figure this out and clean it up ! you guys are awesome. What is the best way to access my flashdrive through the terminal like cd'ing into it? because a simple cd /dev/sdb dosent work.
|
/dev/sdb is the device. You need to go to where it is mounted, generally /mnt or /media
|
Haha yes i formated it with the name Backup and then have it CD into /media/Backup and write it to that. but when i do that it says it cannot backup the file .gvfs but i still have about 1 GB of space left on my flashdrive but in the folder .gvfs there is nothing there even when i show hidden files
|
Do an ls -l and make sure you have access to the item.
|
Quote:
and when i try to mount my flashdrive after formatting it in the terminal and this is part of my script Code:
sudo mount /dev/sdb i tried mounting it to a folder i made called usbflash in the mnt directory which worked but now i cant copy the backup to /mnt/usbflash it says i dont have permission even when using sudo |
You might get more answers if you start a new thread for the new topic ...
|
All times are GMT -5. The time now is 07:34 AM. |