我是csh的新手,正在尝试检查参数是否以“-”开头。我试过以下:
if (`echo $var | awk '{print substr($var,0,1)}'` == '-') then
Run Code Online (Sandbox Code Playgroud)
当运行带有参数“ s”的脚本时,我得到
if: Expression syntax
Run Code Online (Sandbox Code Playgroud)
当运行带有参数“ -s”的脚本时,我得到
if: Missing file name
Run Code Online (Sandbox Code Playgroud)
我也试过
if ($var =~ -*) then
Run Code Online (Sandbox Code Playgroud)
当运行带有参数“ -s”的脚本时,我得到
if: Missing file name
Run Code Online (Sandbox Code Playgroud)
's'参数保持沉默,并且不会进入if
if ("$var" =~ -*) then
Run Code Online (Sandbox Code Playgroud)
为我解决了问题