2,618 reputation
1615
bio website blog.denniswilliamson.us
location United States
age
visits member for 2 years, 9 months
seen 2 hours ago
stats profile views 141

Are you a Stackathlete?

Check the standings on


Profile: I'm a Unix/Linux sysadmin


Mar
4
comment determining path to sourced shell script
@clacke: I find that in all the versions of Bash that I tested from 2.05b to 4.2.37, including 4.1.9, that . and source worked identically in this regard. Note that $_ must be accessed in the first statement in the file, otherwise it will contain the last argument of the previous command. I like to include the shebang for my own reference so I know what shell it's supposed to be for and for the editor so it uses syntax highlighting.
Feb
5
comment How can I scroll within the output of my watch command?
@xav0989: You would need to wrap your chain in curly braces or it will only tail the last command: { command1 && command2 && command3; } | tail - don't forget the spaces (after the opening and before closing brace) and semicolon after the last command. Remember, the whole chain will be executed each time watch reruns it.
Jan
23
comment Is there a way to run 'screen' in read-only mode?
@StephaneChazelas: I don't see any indication in the question that the OP is concerned about writability in other instances of a multiply-attached session. Besides, the aclcng command can specify particular users, particular commands and/or particular windows so that's fairly fine granularity. So that's not "everywhere".
Jul
20
comment Why does this compound command report errors when copying directories?
By "redirected" I assume you mean aliased. The -i option shouldn't cause the problem you're seeing. Is dir2 a symlink? That shouldn't matter, though.
Jul
20
comment Why does this compound command report errors when copying directories?
Do you get an error without -a? What happens if you use -d instead? Is dir2 a symlink?
Jul
20
comment Why does this compound command report errors when copying directories?
There's nothing wrong with the command line you posted. Check to see if either command is aliased or redefined as a function: type -a rm cp.
Jul
1
comment Storing output of command in shell variable
I forgot to say @Patrick in that last comment.
Jun
28
comment What does dash “-” at the end of a command mean?
"redundant and slightly weird" - Sometimes being explicit aids in clarity.
Jun
28
comment Storing output of command in shell variable
Piping sleep to cat is nonsensical, but perhaps useful for some types of testing. If pipes and redirection were the same, then piping into while wouldn't set up a subshell. Also, process substitution uses named pipes or /dev/fd. So, now try your tests, but add & echo $! at the end and do ls -l /proc/PID/fd in another teminal, substituting the PID that was echoed. Seriously, just try it.
Jun
28
comment Storing output of command in shell variable
@Patrick: No, they don't. They do have similarities, but they're different.
Jun
28
comment Storing output of command in shell variable
@Patrick: That's not a pipe, it's redirection. It's process substitution redirected into done.
Jun
4
comment In linux, would it be possible to run a script every day 3 minutes later than the previous day?
Here's a script I wrote to reschedule at jobs. It's not pertinent to the question, but it's tangentially related.
Jun
4
comment In linux, would it be possible to run a script every day 3 minutes later than the previous day?
@KeithThompson: But then you have to keep a counter and increment it.
Jun
4
comment In linux, would it be possible to run a script every day 3 minutes later than the previous day?
@Elmer: Oops! You are correct (except that you can't do running addition). I'll edit my answer.
May
31
comment bash using a file name as input
echo "opening '$first_u_file'" - you don't need to escape the single quotes and the variable gets properly quoted.
Mar
28
comment Accessing bash [internal] brace expansion iteration number/variable
Bash has some special variables/parameters, but nothing like Perl's $_. As I said before, "What are you really trying to accomplish?" See the echo example in l0b0's answer. There's no internal or implied variable. The expansion gets expanded all at once. The iteration is performed over the completed expansion by a for statement using a variable you supply. Bash has no concept of iterators in the sense that Python or Perl have.
Mar
28
comment Accessing bash [internal] brace expansion iteration number/variable
And, ultimately, the question is "Why?". What are you really trying to accomplish?
Mar
28
comment Accessing bash [internal] brace expansion iteration number/variable
"As you can see, bash is setting the iteration to $a" - because you're using a for loop.
Mar
28
comment Accessing bash [internal] brace expansion iteration number/variable
The output you're showing is not the actual output. It's more like mv 1.something.1 1.something.2 1.something.3 1.something.4 1.something.5 2.something.1 2.something.2 2.something.3 2.something.4 2.something.5 3.something.1 3.something.2 3.something.3 3.something.4 3.something.5 4.something.1 4.something.2 4.something.3 4.something.4 4.something.5 5.something.1 5.something.2 5.something.3 5.something.4 5.something.5 ..something. In other words the brace expansion is expanded completely and not iterated over. You must use a for loop for iteration.
Jan
22
comment How do I redefine a bash function in terms of old definition?
Instead of eval, you can use indirection: local VAL=$(echo ${!1})