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?

Jeff Schaller
68.8k35 gold badges122 silver badges263 bronze badges
asked Jul 30, 2018 at 8:01
3
  • 1
    Other than escaping it? Commented 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. Commented Jul 30, 2018 at 8:38
  • What is "directory command"? Commented 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 ...

answered Jul 30, 2018 at 9:12
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
ctrl-alt-delor
28.7k10 gold badges66 silver badges112 bronze badges
answered Jul 30, 2018 at 9:17

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.