Is it possible with a bash variable to perform multiple substitution strings to one variable?
I have this variable:
echo $clock
TIMEZONE="US/Central"
What I would like to do with bash only it pull out just the "US" part of the variable.. which could be any number of countries.
this is where I am at:
echo ${clock:10}
US/Central"
echo ${clock:10#/}
bash: testing: 10#/: syntax error: operand expected (error token is "/")
echo ${clock#*/}
Central"
So, am I just missing something.. or can I only do one type of substition with a bash variable?
thanks,
Trey
Try this:
echo $clock | sed 's!.*"\(.*\)/.*!\1!'
Regards
colemar@deb:~$ echo ${clock:10:2}
US
colemar@deb:~$ a=${clock#*\"}
colemar@deb:~$ echo $a
US/Central"
colemar@deb:~$ echo ${a%%/*}
US
thanks, but I was really just wondering if I could do this all with bash. :o
I know that, but the problem lies that US is not alway US thus it can be more then 2 characters long...
Then you must do it in two steps, as outlined above.
I believe there is no way to do it at once with bash parameters substitution.
Seems to be possible, though ugly:
colemar@deb:~$ echo ${clock//@(*?=\"|\/*?)/}
US
looks like that will do it, good stuff. I appreciate it. This will save me a lot of work creating a bunch of variables in a script