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?

  • 1
    Other than escaping it? – Ignacio Vazquez-Abrams Jul 30 '18 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 '18 at 8:38
  • What is “directory command”? – ctrl-alt-delor Jul 30 '18 at 9:08
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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