jahsiotr
jahsiotr

Reputation: 141

C Shell - How to check if argument starts with '-' character?

I am new to csh and trying to check if argument starts with '-'. I've tried following:

if (`echo $var | awk '{print substr($var,0,1)}'` == '-') then

When running script with argument 's', I get

if: Expression syntax

When running script with argument '-s', I get

if: Missing file name

I also tried

if ($var =~ -*) then

When running a script with argument '-s', I get

if: Missing file name

's' argument stays silent and does not get inside of if

Upvotes: 2

Views: 4694

Answers (1)

jahsiotr
jahsiotr

Reputation: 141

if ("$var" =~ -*) then

has solved the problem for me

Upvotes: 7

Related Questions