Link to home
Start Free TrialLog in
Avatar of rares_dumitrescu
rares_dumitrescu

asked on

Bash - check the first letter of a var

while [ -z $cnickname ] || echo ${cnickname:0:1} | grep [:digit:];
do
if echo ${cnickname:0:1} | grep [:digit:]; then
something

When i execute this it says: Syntax error: Bad substitution, any ideea whats wrong ?
The script should take the virst letter of $cnickname and see if its a digit, and if it is do something
Avatar of ozo
ozo
Flag of United States of America image

Are you sure you are running it in bash and not in sh?
Avatar of rares_dumitrescu
rares_dumitrescu

ASKER

you're right i was using /bin/sh, i changed it to #!/usr/local/bin/bash .. now it works but the if, or while does not turn on at echo ${cnickname:0:1} | grep [:digit:]; when i put something like '3blah'
worked
i know i might sound very stupid, but, why didn't it worked with /bin/sh and it works with /bin/bash ?
whats the difference ? (i am making some scripts on a server, like getegg getpsy etc (for irc) using dialog menu)
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial