Results 1 to 4 of 4
Is it possible to set up a catch-all for bash script's variables?
For instance, imagine that $VAR could return either "abc-123" and "abc-456", but also "def-123" and "def-456".
Is it ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 02-06-2013 #1
Catch-all for bash variables?
Is it possible to set up a catch-all for bash script's variables?
For instance, imagine that $VAR could return either "abc-123" and "abc-456", but also "def-123" and "def-456".
Is it possible to make a script that, depending on if $VAR returns something with "abc" in the beginning does something, but when $VAR returns something beginning with "def" does something different?
Thanks!
- 02-06-2013 #2
You are probably looking for the "case" statement
Testing and BranchingYou must always face the curtain with a bow.
- 02-06-2013 #3Linux Newbie
- Join Date
- Mar 2010
- Posts
- 152
Yes, you can use a case statement:
Code:case "$1" in abc*) # Gets executed if first arg starts with "abc". echo "Saw abc-something" ;; def*) # Gets executed if first arg starts with "def". echo "Saw def-something" ;; *) # Gets executed if previous forms didn't match. echo "Dunnow" ;; esacProgramming and other random guff: cat /dev/thoughts > blogspot.com (previously prognix.blogspot.com)
- 02-06-2013 #4


2Likes


