5 ms·
Could you explain what this line of code does? ssh -t user@example.com "$(< ./my-setup-script.sh)"
by snissn 9y ago
Could you explain what this line of code does?
ssh -t user@example.com "$(< ./my-setup-script.sh)"
- ianbicking 9y agoLooks like a fancier version of ssh -t user@example.com "$(cat ./my-setup-script.sh)" I'll have to file this away myself!
- drdaeman 9y agoNot fancier, just a bash-ism that may not work with some other shells. [bash] https://www.gnu.org/software/bash/manual/html_node/Command-Substitution.html https://www.gnu.org/software/bash/manual/html_node/Command-S... [posix] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_03 http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3...
- cynicalbastard 9y agoit runs the local contents of ./my-setup-script.sh on the remote server in a way that escapes all the special characters so they don't do unexpected things.
- pchm 9y agoIt allows you to run a local shell script on the server via ssh, using bash command substitution - the "$(<" part. The -t option (force tty) executes the script in an interactive session - without it stuff like password prompts won't work (if I remember correctly).
- deleted 9y ago[deleted]
- falsedan 9y agoIt's a weird way of writing ssh -t user@example.com /bin/bash < my-setup-script.sh That is, take the contents of the local file 'my-setup-script.sh' and run them as commands on example.com as the 'user' user (using SSH to authenticate the user & transport the commands).
- iso-8859-1 9y agoBut that might fail half-way through the file, and the other one is all or nothing, might just report "argument list too long".
- falsedan 9y ago> might fail half-way through the file Oh, while transferring! ssh -t user@example.org bash <( echo "function do_it() {"; cat my-setup-script.sh; echo -e "}\ndo_it" ) No argument limits to worry about, no quoting hassles.