0
votes
1answer
32 views

Prompting when redirecting content of script to remote machine

I have simple script: #!/bin/bash while getopts ":u:" opt; do case $opt in u) USER="${OPTARG}" ;; \?) echo "Unknown flag has been used: -$OPTARG" >&2 exit 1 ...
16
votes
5answers
1k views

Using while loop to ssh to multiple servers

I have a file servers.txt, with list of servers: server1.mydomain.com server2.mydomain.com server3.mydomain.com when I read the file line by line with while and echo each line, all works as ...
12
votes
3answers
293 views

When to use redirection to stderr in shell scripts

I know that well-behaved utilities like grep output "normal" messages to stdout, and error messages to stderr. $ grep '^foo' file1 file2 file1:foo grep: file2: No such file or directory When I'm ...
2
votes
4answers
142 views

store and execute redirection/piped command in script

How do you store, and later execute, a command with redirection and and a pipe? (And is it the pipe, or the redirection, or both, that's causing my problem?) I tried to print the urxvt version in a ...
3
votes
2answers
380 views

How to add a line to a file which has only root write permission and to continue the script execution

I am trying to learn bash scripting. I am working on a practical problem and at one point I need to add a line to a file which requires root permission to write. The code looks like this: # some ...
4
votes
3answers
632 views

What does the following Bash script mean/do?

What does the following script mean? exec 4<&0 0</etc/XX/cfg read line1 exec 0<&4 UPDATE Thanks for the answer, just one part I'm not sure: It redirects fd0 to fd4, and ...
2
votes
1answer
921 views

shorthand for feeding contents of multiple files to the stdin of a script

Hi good people of this community, Say I have a script called script, that reads from stdin and spits out some results to the screen. If I wanted to feed it contents of one file, I would have typed: ...
6
votes
2answers
2k views

Iterate over the output of a command in bash without a subshell

I want to loop over the output of a command without creating a sub-shell or using a temporary file. The initial version of of my script looked like this, but this doesn't work since it creates a ...