I have a script as below:
# /brickos/util/f.sh
set folder=`pwd`
cd /brickos/boot
make
firmdl3 -f brickOS.srec
cd $folder
when I run it in cygwin(minty.exe), I got error as below, but when I run them in terminal directly, no any errors! what can I do?
$ f.sh
/cygdrive/c/cygwin/brickos/util/f.sh: line 2: cd: /brickos/boot
: No such file or directory
/cygdrive/c/cygwin/brickos/util/f.sh: line 3: $'make\r': command not found
firmdl3: ERROR- failed to open brickOS.srec
/cygdrive/c/cygwin/brickos/util/f.sh: line 5: cd:
: No such file or directory
$'make\r': command not found
suggests the script is saved with Windows (CRLF) instead of Unix style (just LF) line endings. Try converting it to Unix format and see if that improves matters.
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 just installed CygWin and curl because I wanted to do something unrelated. But now, I want to execute a .lua file in CygWin and I want the results to print on the current window, the CygWin window. I want it to be like the equivalent of just opening CMD and then do cd <directory where the file is>. And then just do <filename>.lua and it prints the results. So how would I go about doing that? Sorry, I'm kinda new to Linux, Unix, CLI, ect., and I don't know much about the bash command.
I tried using the method from here: How do I execute a file in Cygwin?
I just did ./<filename>.lua and I get
./<filename>.lua: line 1: syntax error near unexpected token `"Hello world"'
./<filename>.lua: line 1: `print("Hello world")'
The file just has
print("hello world")
If your file is marked as an executable, running ./<filename>.lua will default to executing the file as a shell script, (i.e., sh, bash, zsh, etc.). This results in the error you see, which is easily recreated.
In bash:
$ echo 'print("Hello world")' > script.sh && chmod +x script.sh && ./script.sh
./script.sh: line 1: syntax error near unexpected token `"Hello world"'
./script.sh: line 1: `print("Hello world")'
The first thing you need to do is make sure Lua is installed (rerun the Cygwin setup GUI, or use a tool like apt-cyg), and is located in your $PATH.
Then instead of executing the file directly, run it with the Lua interpreter.
$ lua <filename>.lua
Alternatively, use a shebang directive to instruct the shell on how the file should be executed.
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 updated my .bashrc with following text to run ns2 and saved it.
export PATH=$PATH:/home/user/nsallinone-2.34/bin:/home/user/ns-allinone-2.34/tcl8.4.18/unix:/home/user/ns-allinone-2.34/tk8.4.18/unix
export LD_LIBRARY_PATH=/home/user/ns-allinone-2.34/otcl-1.13:/home/user/ns-allinone-2.34/lib
export TCL_LIBRARY=/home/user/nsallinone-2.34/tcl8.4.18/library
Now when i run my Cygwin, each time it displays error as:
-bash: $'\r': command not found
Even now i have removed the above text but it still gives error.
Do i have to recompile ./bashrc, if I have how i will do that?
Now when i run my Cygwin, each time it displays error as:
-bash: $'\r': command not found
It seems that you edited your .bashrc using an application that added CR to the file.
Running dos2unix would remove the CR:
dos2unix /path/to/.bashrc
I saved a python file to my desktop. In order to test it, I used the command prompt. However, my command prompt is located in
C:\Users\Name\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Accessories
To change the current directory, I wrote
cd C:\Users\Name\Desktop
in the command prompt. However, it keeps telling me that I have an "invalid syntax"
>>>cd C:\Users\Name\Desktop
File "<stdin>", line 1
cd C:\Users\Name\Desktop
^
SyntaxError: invalid syntax
Any suggestion to fix this problem?
the >>> prompt indicates you are already running python interpreter.
You need to enter that command from the shell prompt.
Press Ctrl-D to exit Python to the ordinary shell prompt and try again.
P.S: I'm not related to anyway with python Reference : http://ubuntuforums.org/showthread.php?t=1558728
try this on ms-dos
cd\
cd C:\Users\YourUserName\Desktop
python filename.py