qiang8
asked on
Script argument manipulation ...
How am I going to take an argument and then modified it and become another new parameter for my script?
Example: my_script A123
In my script, I shall add let say "MS" in front of argv1 and join them together and insert a "." (dot) after the third character of the argv. The new parameter will become "MSA12.3". Then I shall proceed further to manipulate this parameter.
Thanks.
Example: my_script A123
In my script, I shall add let say "MS" in front of argv1 and join them together and insert a "." (dot) after the third character of the argv. The new parameter will become "MSA12.3". Then I shall proceed further to manipulate this parameter.
Thanks.
except in ksh (not shure about bash, zsh), you cannot modify positional parameters, you need to copy them to internal variables, then see ozo's suggestion
ASKER
I have tried the following in csh but none can work .....
Example: my_script A123
Contents are as follow:
1.
#!/bin/csh -f
awk 'END{print "MS"substr (x,0,3) "." substr(x,4)}' x=$1
2.
#!/bin/csh -f
awk '{print "MS"substr(x,0,3)} x=$1 '
3.
#!/bin/csh -f
awk 'END{print "MS"substr($1,0,3)"." substr($1,4)}'
Pls advise.
Example: my_script A123
Contents are as follow:
1.
#!/bin/csh -f
awk 'END{print "MS"substr (x,0,3) "." substr(x,4)}' x=$1
2.
#!/bin/csh -f
awk '{print "MS"substr(x,0,3)} x=$1 '
3.
#!/bin/csh -f
awk 'END{print "MS"substr($1,0,3)"." substr($1,4)}'
Pls advise.
set argv[1]=`awk 'END{print "MS"substr(x,0,3) "." substr(x,4)}' x=$1`
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
here a very basic response using regular expressions, sed & expr, well-working in all environments unix
end=`expr $1 : '.*\(.\)$'`
mid=`echo $1 | (sed -e s/.$/./)`
result=MSA$mid$end
echo $result
typîng hello, will produce MSAhell.o
beware at quotes, antiquotes, slash ans antislash
end=`expr $1 : '.*\(.\)$'`
mid=`echo $1 | (sed -e s/.$/./)`
result=MSA$mid$end
echo $result
typîng hello, will produce MSAhell.o
beware at quotes, antiquotes, slash ans antislash
bedot, is *sh syntax, not *csh,
also the argument contains no dot as you assume in your expr
also the argument contains no dot as you assume in your expr
ASKER
Thanks a lot ...
AHOFF: i don't assume dots: in a regular expression a dot represent any character
oops, should use lynx, or change my browser's font
sorry for incorrectly reading, bedot.
sorry for incorrectly reading, bedot.
set -- `awk 'END{print "MS"substr(x,0,3)"."substr