Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set default user variable in csh scripting

Tags:

shell

csh

I am writing a csh shell script, run where the user is expected to pass a path into it as the $1 variable. How can I determine if $1 is missing and define a default value instead for it?

like image 849
Elpezmuerto Avatar asked Aug 25 '26 10:08

Elpezmuerto


1 Answers

This is know to work on tcsh version 6.15.00

#! /bin/csh

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

echo "The file is $filename."

NOTE
There is no standard with csh as there is with the POSIX shell; but at least basic if-then-else and $#argv should be portable.

See Also
POSIX and Korn Shell Versus Other Shells
Csh Programming Considered Harmful
Bash

like image 180
frayser Avatar answered Aug 30 '26 22:08

frayser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!