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.
The Advanced Bash Scripting Guide (the last link in chrism01's post above) has a whole page specifically dedicated to describing all the reserved/special characters used in bash, and how they are used. Check it out.
Can anyone else verify what uhelp claims? I've seen the ABS recommended many times on this and other sites, and this is the first time I've seen negative criticism of it.
-n nchars return after reading NCHARS characters rather than waiting
for a newline, but honor a delimiter if fewer than NCHARS
characters are read before the delimiter
The -n option to read will not detect the ENTER (newline) key.
There are some more things, which aren't correct.
As I'm not anymore familiar with ABS and therefore did not find all these issues anymore.
Some of them might be have been corrected.
They claimed that the "cd" command would not set it's return value properly.
Prove this wrong with
Code:
mkdir -p a/b
cd a
printf $?'\n'
cd a
printf $?'\n'
They also claimed that using
Code:
cd //
pwd
does not work properly.
As "/" is just a path separator you can use "//", wherever you feel to.
It separates just e.g. /home//somebody the two dirs with a separator nothing and another separator.
It is very misleading to blame "cd" for this.
Correct is, that you have to take care about this thing, when writing code to parse a path.
I think this enough to be at least very critical when using ABS.
Use the links I posted earlier in this thread.
Thanks for the detailed explanation, uhelp
True, "The -n option to read will not detect the ENTER (newline) key" is not correct as shown by this command line experiment:
Code:
read -d '' -n1 -r -s
echo "'$REPLY'"
I can't find the text about cd's return value not being set correctly.
The "The cd command does not function as expected when presented with two forward slashes comment is questionable. Bash functions "as designed" in this regard but I would have designed it differently.
But on the command line I have always related the '&' to end commands or join commands.
The & used like that does "end a command". It puts the first command into the background then runs the second command. In the example given the command, gedit, works in the background so no problem. The same technique used with a command that does not work in the background -- such as vi -- would behave less usefully.
Safer to use ; to separate commands on the same line that are intended to be run in sequence (and subshells to run commands at the same time) because the result is more predictable.
"Join commands" could mean several different things ...
I can't find the text about cd's return value not being set correctly.
Well, I came across these issues some years ago.
It could be that this mistake has already been fixed.
I hat a short look at ABS to find one point to show here.
They also recommended that one should use only capitalized vars, which is quite stupid.
I did not see this recommendation today. May be this is fixed to, as I've seen some vars not capitalized.
The & used like that does "end a command". It puts the first command into the background then runs the second command. In the example given the command, gedit, works in the background so no problem. The same technique used with a command that does not work in the background -- such as vi -- would behave less usefully.
Safer to use ; to separate commands on the same line that are intended to be run in sequence (and subshells to run commands at the same time) because the result is more predictable.
"Join commands" could mean several different things ...
Oh I have to do more research. I tested:
nano;gedit;gedit -- didn't work - until I closed nano - then 2 gedit tabs
gedit;gedit;nano -- worked fine
I need more research on "symbols" just like Knightron was asking ....
I see & ; | && ;; || and combinations of them ... and more ... dizzy...
Back to the manuals
Thank you Catkin
I would say that the only real problem with the ABSG is that it gets updated rarely and sporadically, so changes and bugs that have been fixed are not always reflected accurately. It's one of those documents that long ago reached a relatively complete state, and now only gets attention when absolutely necessary.
I'll agree that it's generally not the first place to send a newbie, except in regards to specific topics like this one, but it remains one of the most useful and detailed guides to bash scripting, IMO.
@Sector11
The semicolon list operator is exactly equivalent to a newline as a command terminator. When the first command terminates, the second command is executed. The following two sets of commands are identical:
Code:
nano
gedit
nano
nano ; gedit ; nano
&& and || are conditional sequencers. && executes the second command only if the first one terminates successfully (gives an exit code of 0). This is particularly useful if the operation of the second command depends on what the first command does. Take this example:
Code:
cd dir ; rm -f * #cd to dir, then run rm (unconditionally)
cd dir && rm -f * #cd to dir, and if successful run rm (otherwise do nothing)
Without the conditional operator, if the cd command failed (e.g. dir doesn't exist), then you'd end up deleting everything in the directory you started in!
|| conversely executes the second command only if the first one exits unsuccessfully (exit code >0). This lets you specify an alternate command if something goes wrong with the first one.
Code:
cd dir || echo "Failed to change directories!"
And as explained, & is a terminator that forks the command off as a background sub-process, and then frees up the terminal in order to immediately execute the next command. It's quite appropriate to use it in the way you posted; catkin's caution was simply that you can't effectively background interactive commands that run directly in the terminal, like vim or nano. They simply get sent into the background in a suspended state and remain there until manually foregrounded or killed.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.