1,599 reputation
18
bio website
location
age
visits member for 1 year, 10 months
seen 9 hours ago

17h
comment How to debug a bash script?
-v can also help (prints out each line as they get executed. can be combined with -x). And see also : bashdb.sourceforge.net
17h
comment Bash: Variable assignment doesn't seem to 'stick'
Bash (and possibly other shells) pitfall's number 8 ( mywiki.wooledge.org/BashPitfalls )
Sep
10
comment “Can't cd to /home/user” when sourcing a script
+1, but maybe add just an explanation: in linux, the CR (Carriage return) (^M) extra character causes the cursor to return to the beginning of the line. And it is also interpreted as part of the directory names. So it really says something like cd: /^M: No such file or directory and the ^M place cursor at the beginning, so the rest of the message "overwrites" the beginning. In the 2nd example, cursor only comes back to beginning as the last character on the line, therefore it's "invisible" that it does so. try your_script 2>&1 | cat -ve : -v to show special chars, -e to end lines with $
Sep
8
comment how to mount a range of drives in bash?
@alipoor.r: And if the paths are stable, edit /etc/fstab with the appropriate infos, and in the loop above just use mount /dev/sd${m} (ie, juste the source, no destination) and each time linux will look into /etc/fstab to know where that particular device should be mounted
Sep
5
comment Remove all files/directories except for one file
@shadur: well, I can relate to them: oneliners are attractive... ^^
Sep
5
comment Remove all files/directories except for one file
move the one you want to keep, then rm the others?
Sep
5
comment Remove all files/directories except for one file
Specifying the directory is good practice (fullpath in this case? or maybe add a warning here that this command deletes every file starting from the current working directory ?). I also usually write any example with rm as echo rm instead, and ask people to only take out the echo when they are really sure it will do what they want. Other than that, +1 for the thorough answer
Sep
4
comment How to tell if SSH'd into machine?
careful, on some OpenSSH clients, this terminates the ssh connection!
Sep
4
comment Command to output file content to stdout?
+1, answer is more accurate (about meaning of cat), more complete (alternatives), and researched (syscalls)
Sep
4
comment Command to output file content to stdout?
@Jan: I disagree that "the purpose of cat is exactly that": it's broader (to concatenate, as the name implies), and outputing a single file to stdout is a nice side effect of that. see my comment to confused00.
Sep
4
comment Command to output file content to stdout?
@MarcvanLeeuwen: I guess he meant "2 file descriptors" instead of "2 files" ... cat reads from stdin (or at least one file) and outputs to stdout. 2 fd. But then the "cat joins its input to its output" shows quite a bit of confusion ^^
Sep
4
comment Command to output file content to stdout?
@confused00: cat was really meant to concatenate (cat file1 file2 will concatenate both files to stdout). But it's side effect is that, when only having 1 file as argument, it outputs that one file to stdout (wherever that goes, either your terminal, or redirected to something). So there was no other command created just to output on stdout, as cat existed and allowed it simply. Therefore you want to use cat.
Sep
4
revised Which is more widely used: chmod 777 or chmod a+rwx
added best practice + link to wikipedia (instead of a long complex description)
Sep
4
comment why 'echo --help' doesn't give me help page of echo?
@MichaelHomer and @Gnouc: in bash command something bypasses and alias -or- function named "something", but not builtins. \something only bypass alias. so indeed enable -n something ; command something would ensure you call the one in the PATH (wherever it is, if any)
Sep
4
comment why 'echo --help' doesn't give me help page of echo?
@boksee: in bash, use type -all echo to see which one is used (and what others there are visible, builtin/alias/function/in the path)
Sep
4
comment Which is more widely used: chmod 777 or chmod a+rwx
@Kevdog777: if only root and the user need access : chmod 00600 (if no need to execute the file) or chmod 00700 (if needs to execute the file -or- it's a directory). or chmod 00400 to add a (tiny, easily overridden) protection against modifying/writing to the file (00500 for a directory). Then others (and people in the group but not the user) can't access the file/dir. (following dotandcohen note, I add the 4th octal in there + a "0" before it: makes no difference for the shell, but helps if you set via perl/C/etc and the 4th octal is a kind of reminder that it exists, and that it is set too)
Sep
4
comment Which is more widely used: chmod 777 or chmod a+rwx
@Kevdog777: Others is for people not the owner nor in the group, aka everyone else on the system
Sep
4
comment Which is more widely used: chmod 777 or chmod a+rwx
+1 for your note, as it is indeed good to always prepend a 0 (even if setting all 4 octals: 01777 for example) as it makes no difference to the shell, but ensure C, perl and others interpret it as octal
Sep
4
revised Which is more widely used: chmod 777 or chmod a+rwx
corrected typo "rws" to "rwx"
Sep
3
awarded  Nice Answer