0

I'm trying to make a script that creates a temporary folder with a particular name, specifically the base name of the folder I'm running the script from. To do this I've tried to do this with the following approach.

setenv suffix $(basename $PWD)
mkdir /tmp/userid_$suffix

But this fails with an illegal variable name error. I can't seem to figure this out after looking a number of sites and questions on here. How can I add the base name of the current folder to a new folder, either in one step or with setting a variable?

  • you know about mktemp -d ? – Archemar Aug 2 '17 at 8:07
2

The following works a lot better:

 setenv suffix `basename $PWD`

You indicated /bin/tcsh as your shell.

  • Neither csh nor tcsh support $(...) style command substitution. backticks `...` don't just "work a lot better", they are required. – cas Aug 2 '17 at 3:41
1

And since you are in csh, it can very simply be written as:

mkdir "/tmp/userid_${cwd:t}"

wherein from the current dir $cwd we can grab it's basename via the :t modifier.

Not the answer you're looking for? Browse other questions tagged or ask your own question.