Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • As a side note. The code need to be improved. Though you could wrap it in a function like TrytoSSH() { your_code_here } then call your function by TrytoSSH Commented Aug 19, 2013 at 11:13
  • Thanks val0x00ff, what about passing parameters and using them inside the method? For example can I call trytoSSH $USERID@$HOST $SCRIPT_PATH/runme.sh and use them in my function with $1, $2 , $3 ? And sometimes parameters to ssh might be different in number also so I want "ssh $USERID@$HOST $SCRIPT_LOCATION/runme.sh " or ssh -t $USERID@$HOST $SCRIPT_LOCATION/runme.sh " as single parameter and want to replace it directly with ssh. Commented Aug 19, 2013 at 11:27
  • You certainly can. You can use "$1" "$2" positional parameters to achieve this. The command will be like ssh -t "$1" "$2" where positional parameter "$1" is user@host and "$2" is your script. Commented Aug 19, 2013 at 11:30
  • @val0x00ff Is quoting the positional parameter really necessary? With spaces you are ****ed already before passing the parameters. Other side note to java_enthu: why not using a for loop? Commented Aug 19, 2013 at 11:41
  • @Bernhard Not really, it's more a habit. I always quote the vars even though not needed. Commented Aug 19, 2013 at 11:49