ksh variable manipulation and processing

Need some programming tips.

I have script, part is
-------------------
#!/bin/ksh
echo ${*} > /tmp/test.txt
exit 0
----------------------
${*} is in one line:

-Ame -Btd -p 1234566 -l var1=n1 n2 n3 -l var2=m1 m2 m3 -l ema=me@host.com -l out=/tmp/tmp.1233.txt

I want to make a new variable that will copy ${*} content to a new ${myvar} as below.

-Ame -Btd -p 1234566 -l var1="n1 n2 n3"  -l var2="m1 m2 m3" -l ema=me@host.com -l out=/tmp/tmp.1233.txt

Mr_PC2000Asked:
Who is Participating?
 
ahoffmannConnect With a Mentor Commented:
myvar="$@"
0
 
chris_calabreseCommented:
$* references all the arguments as a big long string.

What you want is "$@" which references them as an array of strings

If you want to use this to call another program (the most likely case) then you'd just do something like
  other-program "$@"

Otherwise, the following code snippet will set $myvar as a big long string with double-quotes around each entry:

myvar=""
while [ $# -gt 0 ]
do  myvar="$myvar \"$1\""
      shift
done
0
 
Mr_PC2000Author Commented:
Thank you chris_calabrese. Here what I have cooked so far. Give a proximate thought if I am in right direction.

#!/bin/ksh
...
FILEIMPORTANT=file2.txt

pl_numer=""
v_var1 =""
v_var2 =""
myvar = ""

while [ [ $# -gt 0 ] ; do
    case $1 in
    -p)
        pl_number="$2"
        shift; shift;;
    -var1)
        v_var1="\"$2\""
        shift; shift;;
    -var2)
        v_var2="\"$2\""
        shift; shift;;
      )
        argv_command=$1
        shift;;
    esac
done

args="-p "'"'"$pl_number"'"'" -l var1="'"'"$v_var1"'"' -l var2=="'"'"$v_var1"'"'

eval "command $args '/tmp/${FILEIMPORTANT}'"


it is friday, kind of messy will this mean: command -p 1234566 -l var1="n1 n2 n3" -l var2="m1 m2 m3" ??


0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.