The tr command translates, delete, or squeezes characters from standard input. I am trying to create a cshell alias that outputs the setenv
command such that each file or directory in the path is displayed on a new line.
In other words, I want this example output of setenv
:
PATH=/some/dir:/some/second/dir:/some/third/dir
PROFILES= file:///some/file/here.txt;file:///some/second/file.xml;file:///some/third/file/there.pl
To become this:
PATH= /some/dir
/some/second/dir
/some/third/dir
PROFILES= file:///some/file/here.txt
file:///some/second/file.xml
file:///some/third/file/there.pl
I have created aliases that output the individual environment variables like above:
alias readablePath = 'echo "$PATH" | tr : '\'\\\n\'' '
alias readableProfiles= 'echo "$PROFILES" | tr \; 'echo "$PATH" | tr : '\'\\\n\'' '
These are the aliases that I have tried that return tr: no match
.
alias readEnv 'echo "setenv" | tr [:\;] '\'\\\n\'' '
alias readEnv 'echo setenv | tr [:\;] '\'\\\n\'' '
alias readEnv 'echo setenv | tr [:\\;] '\'\\\n\'' '
alias readEnv 'echo setenv | tr [:;] '\'\\\n\'' '
These are the aliases that I have tried that return the string "setenv"
.
alias readEnv 'echo setenv | tr "[:;]" '\'\\\n\'' '
alias readEnv 'echo "setenv" | tr "[:;]" '\'\\\n\'' '
How do I create an alias that successfully takes the output of setenv
and inserts a newline where there is a ":" or a ";"?
To replace multiple characters in your (unix/linux) command line alias, you should rather use sed and regular expressions, as in Search and replace with sed when dots and underscores are present .
So something like:
sed 's/\.\|,/\\n/g'
where \.
finds a dot (needs to be escaped, else it finds any character), \|
is the or operation, also escaped, and the new line also must have its \\
escaped.