5 added 561 characters in body
source | link

For example:

safer_scp() (
  file=$1; shift
  export LC_SCPFILES="${file#*:}"
  exec scp -o SendEnv=LC_SCPFILES "${file%%:*}:</dev/null
    zsh -o extendedglob -o globsubst -c 'exec scp -f -- \$LC_SCPFILES';exit" "$@"
)
safer_scp user@host:'file-name-version-<->(.<->)#.jar' .

Would copy file-name-version-1.jar and file-name-version-1.2.3.4.5.jar (<x-y> is any decimal integer number from x to y, <-> is any decimal integer number, # is like the * regexp operator (0 or more of the preceding atom))

For example:

safer_scp() (
  file=$1; shift
  export LC_SCPFILES="${file#*:}"
  exec scp -o SendEnv=LC_SCPFILES "${file%%:*}:</dev/null
    zsh -o extendedglob -o globsubst -c 'exec scp -f -- \$LC_SCPFILES';exit" "$@"
)
safer_scp user@host:'file-name-version-<->(.<->)#.jar' .

Would copy file-name-version-1.jar and file-name-version-1.2.3.4.5.jar (<x-y> is any decimal integer number from x to y, <-> is any decimal integer number, # is like the * regexp operator (0 or more of the preceding atom))

4 added 18 characters in body
source | link

Because its stdin is redirected from /dev/null, the first scp will exit straight away. Then we start our shell of choice (bash), with the extglob option, and with the exec scp -f -- $LC_SCPFILES command line to interpret.

Because bash will run in a child process of that-shell (which we enforce by adding a ;exit afterwards), bash will not source the ~/.bashrc, so we can expect the default behaviour of bash there (unless somehow that-shell, on startup, sets the BASHOPTS, SHELLOPTS or BASH_ENV environment variables).

Because its stdin is redirected from /dev/null, the first scp will exit straight away. Then we start our shell of choice (bash), with the extglob option, and with the scp -f -- $LC_SCPFILES command line to interpret.

Because bash will run in a child process of that-shell (which we enforce by adding a ;exit afterwards), bash will not source the ~/.bashrc, so we can expect the default behaviour of bash there (unless somehow that-shell sets the BASHOPTS, SHELLOPTS or BASH_ENV environment variables).

Because its stdin is redirected from /dev/null, the first scp will exit straight away. Then we start our shell of choice (bash), with the extglob option, and with the exec scp -f -- $LC_SCPFILES command line to interpret.

Because bash will run in a child process of that-shell (which we enforce by adding a ;exit afterwards), bash will not source the ~/.bashrc, so we can expect the default behaviour of bash there (unless somehow that-shell, on startup, sets the BASHOPTS, SHELLOPTS or BASH_ENV environment variables).

3 added 446 characters in body
source | link

Note that you can disable word splitting by adding a IFS=; before the exec scp... above.

Also note that we're using bash here on the basis that it's installed on all GNU systems, but if you know zsh is installed on the remote system, you can use

zsh -o extendedglob -o globsust

instead to benefit from the full power of zsh globbing (recursive, qualifiers...)

(add -o shwordsplit if you want word splitting as well).

Note that you can disable word splitting by adding a IFS=; before the exec scp... above.

Also note that we're using bash here on the basis that it's installed on all GNU systems, but if you know zsh is installed on the remote system, you can use

zsh -o extendedglob -o globsust

instead to benefit from the full power of zsh globbing (recursive, qualifiers...)

(add -o shwordsplit if you want word splitting as well).

2 added 301 characters in body
source | link
1
source | link