I checked the /usr/bin/ssh-copy-id
(part of openssh-client
package at least under Debian) shell-script and it contains following if-statement:
if [ "-i" = "$1" ]; then
shift
# check if we have 2 parameters left, if so the first is the new ID file
if [ -n "$2" ]; then
if expr "$1" : ".*\.pub" > /dev/null ; then
ID_FILE="$1"
else
ID_FILE="$1.pub"
fi
shift # and this should leave $1 as the target name
fi
else
What is the point of shift
commands? I mean I know that shift n
shell builtin shifts n
number of arguments from left to right, but what is the reason to use it in this script? Why not use:
if [ "-i" = "$1" ]; then
if [ -n "$3" ]; then
if expr "$2" : ".*\.pub" > /dev/null ; then
ID_FILE="$2"
else
ID_FILE="$2.pub"
fi
fi
case
statement here. – mikeserv Jun 25 '15 at 22:05