Thanks Bob. All the explanation were very helpful. Now I feel I have a good understanding of this little peculiarity of ssh. I agree with you that avoiding quoting altogether is simpler. But I am curious guy and learning for the sake of better understanding is also important to me.
Bob Proulx wrote: > > peter360 wrote: >> Thanks Adreas. That was what I suspected in my reply to Bob. But Bob >> disagreed. Looks like there were some confusion about this feature even >> among experts. Seems another reason to deprecate the feature. > > I don't think anything I said disagreed with what Andreas said. It is > just confusing you since we are talking about different points in the > process. What does the local shell do, what does the ssh do, what > does the remote shell do, what is the end-to-end effect and so forth. > All three processes are handling the arguments and each has an affect > at different points in the timeline. I was talking end-to-end > (shell-ssh-shell) and Andreas was talking about ssh. > > And by the way but this feature can't really be changed or it would > break twenty years or so of scripts which rely upon the existing > behavior. > > Greg Wooledge wrote: >> imadev:~$ $HOME/bin/args 'ulimit -a' >> 1 args: 'ulimit -a' >> imadev:~$ remsh localhost $HOME/bin/args 'ulimit -a' >> 2 args: 'ulimit' '-a' >> imadev:~$ ssh localhost $HOME/bin/args 'ulimit -a' >> wool...@localhost's password: >> 2 args: 'ulimit' '-a' > > Nice! It would also be illustrative to show what happens without any > quoting and with quoting for two shell layers. > > $ $HOME/bin/show-args 'ulimit -a' > arg1: ulimit -a > > $ ssh -n localhost $HOME/bin/show-args ulimit -a > arg1: ulimit > arg2: -a > > $ ssh -n localhost $HOME/bin/show-args 'ulimit -a' > arg1: ulimit > arg2: -a > > $ ssh -n localhost $HOME/bin/show-args '"ulimit -a"' > arg1: ulimit -a > > Since there are two shells splitting words in the end-to-end result > then the effect is that you need to quote your arguments twice in > order to have an argument containing whitespace in one argument by the > time it has been processed through two shell's argument processing. > > Without sufficient quoting you have this following case, which isn't > what you want. The bash shell on the remote end would not see args > "-c" "ulimit -a" but would see "-a" as a separate > > $ ssh -n localhost $HOME/bin/show-args bash -c "ulimit -a" > arg1: bash > arg2: -c > arg3: ulimit > arg4: -a > > That isn't what you want. You need to quote the args twice. > > $ ssh -n localhost $HOME/bin/show-args 'bash -c "ulimit -a"' > arg1: bash > arg2: -c > arg3: ulimit -a > > In the end you want something like this: > > $ ssh -n localhost 'bash -c "ulimit -a"' > core file size (blocks, -c) 0 > data seg size (kbytes, -d) unlimited > scheduling priority (-e) 0 > file size (blocks, -f) unlimited > pending signals (-I) 8185 > max locked memory (kbytes, -l) 32 > max memory size (kbytes, -m) unlimited > open files (-n) 1024 > pipe size (512 bytes, -p) 8 > POSIX message queues (bytes, -q) 819200 > real-time priority (-r) 0 > stack size (kbytes, -s) 8192 > cpu time (seconds, -t) unlimited > max user processes (-u) 8185 > virtual memory (kbytes, -v) unlimited > file locks (-x) unlimited > > However I think it is simpler to avoid the argument processing and > instead using stdin to the shell. > > $ echo ulimit -a | ssh localhost bash > > Isn't that simpler? > > Bob > > > > -- View this message in context: http://old.nabble.com/ulimit-and-ssh--tp25262471p27086055.html Sent from the Gnu - Bash mailing list archive at Nabble.com.