Skip to content

Instantly share code, notes, and snippets.

@christianbundy
Created February 12, 2014 12:33
Show Gist options
  • Save christianbundy/8954786 to your computer and use it in GitHub Desktop.
Save christianbundy/8954786 to your computer and use it in GitHub Desktop.
# let's assume the command is:
# sshcd -v -q [email protected]:/path/to/file
# grabs the last argument of command, the target: "[email protected]:/path/to/file
t="${!#}"
# command to run, which I've broken down line by line
c=(
"ssh"
"-t" # force pseudo-tty allocation (http://www.openbsd.org/cgi-bin/man.cgi?query=ssh&sektion=1)
"${@:1:$(($#-1))}" # list each of the arguments other than the target ("-v -q")
"${t%:*}" # target before the last ":"
"cd ${t##*:}; \$SHELL -l" # target before the first ":", and start the shell
)
"${c[@]}" # run the command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment