using cat command with variable unix -


sh temp1.sh gold.txt silver.txt 2 gold.txt $2 

silver second gold. unique position in competition.

cat: cannot open $2 

tstetlx () /appl/edw/apps/scripts/scenario1> vi temp1.sh i=$# echo $i echo $1 echo $`echo $i` #cat "$`echo $i`" cat $2 cat "\$$i" 

the below command not printing contents of second file passed argument file.

cat "\$$i" 

not clear me trying do. consider using $1 or $2.

the reason line fails because parameter cat literally $2 - no attempt shell substitute $2 if variable.

this 1 way handle problem. note bash solution.

i=$# echo $i echo $1 echo $`echo $i` #cat "$`echo $i`" cat $2 cat "\$$i" declare -a arr=( "$0" $@ ) echo  ${arr[i]} cat ${arr[i]} 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -