0
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'

I found a command to display directory tree (see above), it didn't work correctly. It gave error message "Illegal variable name". I think the error is at $ sign. How can I modify this command for cshell environment?

3
  • 1
    Other than escaping it? Jul 30, 2018 at 8:04
  • 1
    I suspect that I am not the only one enjoying that the answer is given only a few characters further along in the question itself.
    – JdeBP
    Jul 30, 2018 at 8:38
  • What is “directory command”? Jul 30, 2018 at 9:08

2 Answers 2

1

:$ should be in single quotes to stop the shell from expanding it.

so ls -R | grep ':$' | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'


Your next thing to learn, is shell quoting, and expansions.

Also a lot of people consider csh to have been a mistake. It is full of odd inconsistent behaviour. Consider another bash, ksh, fish

1

Instead of a shell script you can use an external commands. 'tree' may be available in your environment, then it's easy.

tree -d

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .