Accessing variable from ARGV

Posted by snaken on Stack Overflow See other posts from Stack Overflow or by snaken
Published on 2010-05-06T11:29:42Z Indexed on 2010/05/06 11:48 UTC
Read the original article Hit count: 237

Filed under:
|
|
|
|

I'm writing a cPanel postwwwact script, if you're not familiar with the script its run after a new account is created. it relies on the user account variable being passed to the script which i then use for various things (creating databases etc). However, I can't seem to find the right way to access the variable i want. I'm not that good with shell scripts so i'd appreciate some advice. I had read somewhere that the value i wanted would be included in $ARGV{'user'} but this simply gives "root" as opposed to the value i need. I've tried looping through all the arguments (list of arguments here) like this:

#!/bin/sh
for var
do
    touch /root/testvars/$var
done

and the value i want is in there, i'm just not sure how to accurately target it. There's info here on doing this with PHP or Perl but i have to do this as a shell script.

EDIT Ideally i would like to be able to call the variable by something other than $1 or $2 etc as this would create issues if an argument is added or removed

Any ideas?

© Stack Overflow or respective owner

Related posts about shell

Related posts about shell-scripting