I am trying to share a Shell script from my Github with people. It is for a workshop and I thought the easiest way would be to have them download it with:
wget https://raw.githubusercontent.com/user/repo/master/script.sh
But I am getting this when I try to run it:
script.sh: line 2: $'\r': command not found
script.sh: line 4: $'\r': command not found
script.sh: line 6: $'\r': command not found
script.sh: line 7: syntax error near unexpected token `$'\r''
'cript.sh: line 7: `helpFunction()
However, it works when I convert it to Unix with dos2unix using:
dos2unix script.sh
How can I avoid having to use this extra step? I am also open to other suggestions about sharing my code in a simple way.
Related
Codenvy is an IDE that removes all files that are in gitignore when the environment you work in goes to sleep. So every time I start working in Codenvy I need to put these files back. That is a hassle and therefore I am trying to add what in Codenvy is called a command (a script) for this.
I have the following:
1. cp vars-user-portal/variables.env user-portal/variables.env
2.
3. cp vars-user-portal/serviceAccountKey.json user-portal/serviceAccountKey.json
4.
5. cp vars-user-portal/.env user-portal/client/.env
6.
7. cd user-portal && npm install
8.
9. cd user-portal/client && npm install
10.
11. xdg-open user-portal/client/.env
When I run this command, I get the output:
/bin/bash: line 1: $'\r': command not found
/bin/bash: line 3: $'\r': command not found
/bin/bash: line 5: $'\r': command not found
Usage: npm <command>
...
Did you mean one of these?
install
uninstall
unstar
/bin/bash: line 7: $'\r': command not found
Usage: npm <command>
...
/bin/bash: line 9: $'\r': command not found
xdg-open: file '.env' does not exist
I have the impression that when there are spaces on a line it sees it as separate commands. Any idea how I can get this script to work?
Your file most likely has \r\n line endings, which should be changed to \n line endings.
A simple way to convert the file with the command line sed utility is as follows.
sed -i 's/\r\n/\n/g' "./path/to/file" (Untested).
In general, Windows applications terminate lines in text files with the 'carriage return' and 'line feed' characters, commonly written as the escape codes \r\n.
On the other hand, Unix-like systems terminate lines with only the line feed, or new as a line ending, which Unix uses just 'line feed' character \n.
See: http://www.cs.toronto.edu/~krueger/csc209h/tut/line-endings.html
Note:
As an additional mention, you should always add a shebang to the top of your script if it is to be executable, or else do not add one if it is to be solely sourced. #!/bin/bash for bash scripts, and #!/bin/sh for portable or POSIX-compliant scripts.
I have configured the HBASE using the below link
https://hbase.apache.org/0.94/cygwin.html
I have configured successfully but unable to run the HBase and the errors that are displayed are not meaningful.
$ ./start-hbase.sh
./start-hbase.sh: line 20: $'\r': command not found
./start-hbase.sh: line 22: $'\r': command not found
./start-hbase.sh: line 28: $'\r': command not found
./start-hbase.sh: line 30: cd: $'.\r': No such file or directory
./start-hbase.sh: line 31: $'\r': command not found
./start-hbase.sh: line 35: $'\r': command not found
: No such file or directory/usr/local/hbase/bin
./start-hbase.sh: line 37: $'\r': command not found
./start-hbase.sh: line 66: syntax error: unexpected end of file
I am unable to understand where to start the debug.
The error is caused by file using CRLF termination instead of expected LF.
Use d2u start-hbase.sh to change it. d2u is part of dos2unix package
I'm trying to run a shell script so I can boot up my local version of a Meteor app that I'm working on. I've never used shell scripts before this, but got the thing running when I was working with the head developer. So this is my run.sh file:
#echo off
c:
cd /Users/ten3/Desktop/git/ten/website/prospect-recovery/prospect-recovery
SET ROOT_URL=http://localhost
SET SPECIAL_RUN=no
SET NO_BATCH=no
SET NO_MAIL=no
SET MAIL_GUN_TEST=yes
SET MAIL_THROTTLE_INTERVAL=0
SET NODE_OPTIONS=%1
SET SHORT_URL=http://sota.ddns.net
SET NODE_PATH=%AppData%\npm
meteor --port 80
echo “works”
I'm pretty clueless as to what these actually do, aside from keep my local copy of the app interacting with other APIs. Every time I try to run the script I get:
run.sh: line 4: #echo: command not found
run.sh: line 6: c:: command not found
run.sh: line 10: SET: command not found
run.sh: line 12: SET: command not found
run.sh: line 14: SET: command not found
run.sh: line 16: SET: command not found
run.sh: line 18: SET: command not found
run.sh: line 20: SET: command not found
run.sh: line 22: SET: command not found
run.sh: line 24: SET: command not found
run.sh: line 26: SET: command not found
Error: listen EACCES
“works”
I've tried changing the file permissions, using sudo, tried including the file location in the paths it looks for it, tried including bash within my file, tried running the file inside the directory run.sh is, pretty much everything I can google. I can't figure out what I'm missing, and would like to die.
You should rewrite it for bash or another shell for a unix-like operating system (there're many alternatives, with bash is the most common).
#!/bin/sh
cd /some/required/path
ROOT_URL='http://localhost'
SPECIAL_RUN='no'
...
NODE_OPTIONS="$1" # notice double quotes, single quotes don't perform $variable expansion
SHORT_URL="http://sota.ddns.net"
NODE_PATH=/actual/path/to/npm
export ROOT_URL SPECIAL_RUN ... NODE_OPTIONS SHORT_URL NODE_PATH
./meteor --port 80 # since the port is below 1024, it's privileged, and the script should be run from root. Use ports > 1024 to run as a user
To run a program or a script from a given directory, you may specify a /full/path/to/the/program or simply include /path/to/the to PATH. By default current directory isn't in PATH for security reasons (unlike in Windows).
I am trying to set JAVA_HOME in env.sh in hadoop. I am using cygwin on Windows 7.
I have edited the env.sh as :
export JAVA_HOME= "/cygdrive/C/Program Files/Java/jdk1.6.0_26"
In environment variables I have set JAVA_HOME as C:\Program Files\Java\jdk1.6.0_26
And the path as %JAVA_HOME%\bin;c:\cygwin\bin;c:\cygwin\usr\sbin
But still I am getting these errors.
/cygdrive/d/hadoop-1.2.1/libexec/../conf/hadoop-env.sh: line 2: $'\r': command not found
/cygdrive/d/hadoop-1.2.1/libexec/../conf/hadoop-env.sh: line 7: $'\r': command not found
': not a valid identifierlibexec/../conf/hadoop-env.sh: line 9: export:
`/cygdrive/C/Program Files/Java/jdk1.6.0_26
/cygdrive/d/hadoop-1.2.1/libexec/../conf/hadoop-env.sh: line 12: $'\r': command not found
/cygdrive/d/hadoop-1.2.1/libexec/../conf/hadoop-env.sh: line 41: $'\r': command not found
/cygdrive/d/hadoop-1.2.1/libexec/../conf/hadoop-env.sh: line 46: $'\r': command not found
/cygdrive/d/hadoop-1.2.1/libexec/../conf/hadoop-env.sh: line 52: $'\r': command not found
/cygdrive/d/hadoop-1.2.1/libexec/../conf/hadoop-env.sh: line 55: $'\r': command not found
Error: JAVA_HOME is not set.
I have checked everything possible on this website but still facing the problem.
Use export JAVA_HOME="C:/PROGRA~2/Java/jdk1.6.0_03" #for 32 bit Java arch
Use export export JAVA_HOME="C:/PROGRA~1/Java/jdk1.6.0_03" #for 64 bit Java arch
This will fix your problem... The answer I am giving is pretty late but it will help others who are beginners facing the same problem.
use C:\"Program Files"\Java\jdk1.6.0_26 instead, that should solve the java problem.
I'm having trouble running Hadoop 1.0.3 on Windows 7 64-bit.
I'm following directions from this link. I've downloaded Cygwin and successfully started the SSH daemon. I unpacked Hadoop into the Cygwin /usr/local folder using Win-Zip 16.5. I edited the hadoop-env.sh to point to my JDK using MetaPad:
export JAVA_HOME="C:\\Program Files\\Java\\jdk1.7.0_02"
I ran dos2unix to make sure that I didn't have any issues with characters.
But when I run the hadoop command in Cygwin terminal to get the version I see this:
$ bin/hadoop version
bin/hadoop: line 2: $'\r': command not found
bin/hadoop: line 17: $'\r': command not found
bin/hadoop: line 18: $'\r': command not found
bin/hadoop: line 49: $'\r': command not found
: No such file or directoryn
bin/hadoop: line 52: $'\r': command not found
bin/hadoop: line 60: syntax error near unexpected token `$'in\r''
'in/hadoop: line 60: `case "`uname`" in
Michael#Michael-PC /usr/local/hadoop
$
Has anyone seen this? Is there an easy correction that I missed?
Seems like carriage return difference between unix and windows is causing the problem .
Try running dos2unix on the shell script
Go to the hadoop bin directory and try :
dos2unix.exe hadoop.sh
And then try the hadoop command .