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?

Tyberius
  • 189

2 Answers2

2

The following works a lot better:

 setenv suffix `basename $PWD`

You indicated /bin/tcsh as your shell.

mdpc
  • 6,834
  • Neither csh nor tcsh support $(...) style command substitution. backticks \...`` don't just "work a lot better", they are required. – cas Aug 02 '17 at 03: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.