Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello,
probably a really basic question, but there it is: does somebody want to tell me why this simple script doesn't work
Code:
#!/bin/bash
unset PATH
BACKUP_DEVICE="/dev/sdg1"
MOUNTING_POINT="/root/snapshot"
mount -o rw $BACKUP_DEVICE $MOUNTING_POINT
Giving the following error message:
Code:
./test.sh: line 8: mount: No such file or directory
While the exact same commands pasted on the terminal work perfectly?
I have similar troubles with other commands, not only “mount”, so I think I’m doing something wrong.
unset PATH means you remove that variable. bash usually uses it, so removing it is not a good idea.
MOUNT should be used as any other variable: $MOUNT.
Hi hazel,
thanks for your hint: actually I've taken the script from the web, but I've made a modification. The original was "slightly" different:
Code:
MOUNT=/bin/mount
...
MOUNT -o rw $BACKUP_DEVICE $MOUNTING_POINT
well, I didn't see a point in doing that chain
@lougavulin: the purpose to unset PATH, based on the source script comments, is to avoid accidental use of $PATH. Do you think it is unnecessary?
1) "Variables hold data. Functions hold code. Don't put code inside variables! " from here: http://mywiki.wooledge.org/BashFAQ/050
(i for one am not that sure in this case, just saying)
2) don't user upper case variables
3) quote *every* substitution
4) #bash IRC bot "Google is NOT a preferred source for learning bash, because almost all the "tutorials" and scripts out there are JUNK." (the reasoning for that harsh comment should be clear from that very short example you found via google).
1) "Variables hold data. Functions hold code. Don't put code inside variables! " from here: http://mywiki.wooledge.org/BashFAQ/050
(i for one am not that sure in this case, just saying)
2) don't user upper case variables
3) quote *every* substitution
4) #bash IRC bot "Google is NOT a preferred source for learning bash, because almost all the "tutorials" and scripts out there are JUNK." (the reasoning for that harsh comment should be clear from that very short example you found via google).
Disagree strongly with #2! In a case-sensitive environment, upper-case variables are recommended.
Disagree strongly with #2! In a case-sensitive environment, upper-case variables are recommended.
recommended by whom? sure not by #bash
Quote:
By convention, environment variables (PATH, EDITOR, SHELL, ...) and internal shell variables (BASH_VERSION, RANDOM, ...) are fully capitalized. All other variable names should be lowercase. Since variable names are case-sensitive, this convention avoids accidentally overriding environmental and internal variables.
1) "Variables hold data. Functions hold code. Don't put code inside variables! " from here: http://mywiki.wooledge.org/BashFAQ/050
(i for one am not that sure in this case, just saying)
2) don't user upper case variables
3) quote *every* substitution
4) #bash IRC bot "Google is NOT a preferred source for learning bash, because almost all the "tutorials" and scripts out there are JUNK."
"this advise" you recommend to ignore is from mywki.wooledge.org, #bash irc channel and wiki.bash-hackers.org.
I gave the links and the quotes for the reasoning, instead of simply a "recommendation". User can decide on their own if it makes sense or not.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.