Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

When I try to run the following script in zsh, via the command /bin/zsh ~/.set_color_scheme.sh I get the following error:

command not found: ^M

The script has u+x permissions and it used to work on another machine that also had zsh. Any clues why?

Note: This question is related to this other question (where I am trying to adapt the script for tcsh)

#!/bin/zsh
# Contents of set_color_scheme.sh

export LS_COLORS=$( \
( grep '\w' | grep -v '^#' | sed 's/#.\+//' | perl -lane 'printf "%s=%s:", shift @F, join ";", @F;' ) <<< "

# HUMAN_FORMATTED_DATA
# list one per line

# these are basic filesystem items
no 00          # normal
fi 00          # file
di 01 34       # directory
ln 00 36       # link
pi 40 33       # pipe
so 00 35       #
bd 40 33 01
cd 40 33 01
or 01 05 37 41
mi 01 05 37 41
ex 00 91       # executable
ow 01 34       # other writables


*.cmd 00 32
*.exe 00 32

# archive, compressed things etc
*.gz  00 90
*.bz2 00 90
*.bz  00 90
*.tz  00 90
*.rpm 00 90
*.rar 00 90
*.zip 00 90
*.iso 00 90


*.cpio 00 31



# perl & CODE
*.c      33
*.h      33
*.sh     33
*.t      33
*.pm     33
*.pl     33
*.cgi    33
*.pod    33
*.PL     33
*.js     33
*.php    33
#*.xs

# strikethrough
*.off 00 9
*.bak 00 9
*.old 00 9


# documents misc, html webstuff
# really TEXT
*.htm    94
*.html   94
*.txt    94
*.text   94
*.css    94


# MOVIE
*.avi    96
*.wmv    96
*.mpeg   96
*.mpg    96
*.mov    96
*.AVI    96
*.WMV    96
*.mkv    96

# images & pdf
*.jpg    96
*.jpeg   96
*.png    96
*.xcf    96
*.JPG    96
*.gif    96
*.svg    96
*.eps 00 96
*.pdf 00 96
*.PDF 00 96
*.ps  00 96

*.ai  00 91 # adobe ill
*.doc 00 91 # msword shit

# data, such as .db, .csv
*.csv    95
*.dsv    95
*.db     95
*.sql    95
*.meta   95
# CONFS
*.xml    95
*.yaml   95
*.yml    95
*.conf   95
# [a-z0-9]*rc
")
share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

Your shell script is in DOS/Windows text format (with CR+LF). Convert it to Unix format (e.g. use dos2unix).

This won't work as you want though, as explained in the linked question. A new shell is executed, the variable it set, then the shell ends, taking the variable with it.

If you have a script that uses the same shell as the one you're running (or has compatible syntax), then you can execute the script by using . or source. This way the script is run as if you typed it all in yourself, so all variables remain (and it will ignore the #! line).

share|improve this answer
    
Thanks @teppic! I see ... How should I run the script set_color_scheme.sh if I don't want to start a new shell? The problem I have is that the way I currently get on zsh is by invoking /bin/zsh from tcsh (the default shell in the system) as we are not "allowed" to change our default shell. My concern is that if source the file via . or source, it may invoke the default shell on it (tcsh), and not zsh. Is my concern unjustified? Should I just use source or . the file after calling /bin/zsh ? –  user815423426 Sep 6 '12 at 1:22
1  
I'll update the main answer with the details. –  teppic Sep 6 '12 at 2:44
1  
I think this error specifically comes from export LS_COLORS=$( \ -- the line continuation char must be the last character on the line and here it is followed by a carriage return. –  glenn jackman Sep 6 '12 at 3:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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