I'm newbie in bash scripting
I want to format command with printf to prepare execution and assign into variable.
But it is executing immediately. It is listing /opt/cinar/packages/libcnrhttp2_*
instead of writing it as string into command string.
I was expecting this:
ssh [email protected] ls /opt/cinar/packages/libcnrhttp2_* -lr | awk 'NR==1'
#!/bin/bash
declare -r libcnrhttp2="libcnrhttp2_"
declare -r root="/opt/cinar/packages"
declare -r destination="/opt/cinar/packages"
declare -r id=ctopkaya
declare -r host=192.168.13.137
declare -r remote=$id"@"$host
declare cmd=""
printf -v cmd ssh %s ls %s/%s* -lr | awk 'NR==1' $remote /opt/cinar/packages libcnrhttp2_
cd $destination
echo "--------------"
echo $cmd
echo "--------------"
$cmd
byprintf -v cmd
usingecho $cmd
. This is why that string is outputted. The generated command in$cmd
is not executed by the script that you show.-lr
options tols
must be before the filenames. Theawk
will only show a single line from the pipe, not the first line of each item in thels
command.