[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ksh variable manipulation and processing

Posted on 2005-04-15
3
Medium Priority
?
631 Views
Last Modified: 2013-12-26
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

0
Comment
Question by:Mr_PC2000
3 Comments
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 13792867
$* 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
 

Author Comment

by:Mr_PC2000
ID: 13794254
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
 
LVL 51

Accepted Solution

by:
ahoffmann earned 1050 total points
ID: 13794301
myvar="$@"
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question