2010-09-28 32 views

回答

0

你可以這樣做:

if [ $# -eq 0 ];then 
     dir='default' # argument not passed use default. 
else 
     dir=$1  # argument passed..use it. 
fi 

# use $dir 
ls $dir 
+1

這就是Bourne和家人見。問題被標記爲[[csh]'。 – 2010-09-28 18:25:03

2

這是知道有關tcsh版本工作00年6月15日

#! /bin/csh 

if($#argv == 0) then 
     set filename="(default file)" 
else 
    set filename=$argv[1] 
endif 

echo "The file is $filename." 

注意
沒有與CSH沒有標準,因爲與POSIX外殼一起;但至少基本的if-then-else$#argv應該是便攜式的。

此外
POSIX and Korn Shell Versus Other Shells
Csh Programming Considered Harmful
Bash

+0

我可以在一行中做到這一點嗎?因爲我需要在別名中使用它 – Shuman 2016-03-28 16:29:23