#!/bin/bash # figure out the absolute path to the script being run a bit # non-obvious, the ${0%/*} pulls the path out of $0, cd's into the # specified directory, then uses $PWD to figure out where that # directory lives - and all this in a subshell, so we don't affect # $PWD GAMEROOT=$(cd "${0%/*}" && echo $PWD) #determine platform UNAME=`uname` if [ "$UNAME" == "Darwin" ]; then # prepend our lib path to LD_LIBRARY_PATH export DYLD_LIBRARY_PATH=${GAMEROOT}:$DYLD_LIBRARY_PATH elif [ "$UNAME" == "Linux" ]; then # prepend our lib path to LD_LIBRARY_PATH export LD_LIBRARY_PATH=${GAMEROOT}:$LD_LIBRARY_PATH fi if [ -z $GAMEEXE ]; then if [ "$UNAME" == "Darwin" ]; then GAMEEXE=hl_osx elif [ "$UNAME" == "Linux" ]; then GAMEEXE=hl_linux fi fi ulimit -n 2048 # and launch the game cd "$GAMEROOT" STATUS=42 while [ $STATUS -eq 42 ]; do ${DEBUGGER} "${GAMEROOT}"/${GAMEEXE} -game dod $@ STATUS=$? done exit $STATUS 

Error text at startup:

 /root/dod.sh: 13: [: Linux: unexpected operator /root/dod.sh: 16: [: Linux: unexpected operator /root/dod.sh: 22: [: Linux: unexpected operator /root/dod.sh: 24: [: Linux: unexpected operator /root/dod.sh: 36: /root/dod.sh: /root/: Permission denied 

The script just does not start. I want to know how to fix this error. I downloaded the toy, dropped it into the folder and run the script. He swears. In Google, I could not find a solution to the error. In this case I am a layman, for this I ask for help. When you run #. / Dod.sh nothing happens When you run #bash ./dod.sh too.

 root@GeenTeen:~$ cat -n dod.sh | grep 16 | hd 00000000 20 20 20 20 31 36 09 65 6c 69 66 20 5b 20 22 24 | 16.elif [ "$| 00000010 55 4e 41 4d 45 22 20 3d 3d 20 22 4c 69 6e 75 78 |UNAME" == "Linux| 00000020 22 20 5d 3b 20 74 68 65 6e 0a |" ]; then.| 0000002a 
  • This is for installing toys - GeenTeen
  • Do you run the script as root? Put in the home directory of the user, on behalf of which you run. - MANKK
  • I have not created users. When installing, only the root was. I let him off. - GeenTeen
  • The code should be in question in the form of text , but not a picture and not in the comments. Okay, the question has been edited. Now explain what the problem is with you, what result you expect to get and what you actually get. Feel free to use the edit button. ) - Nick Volynkin
  • Amazing (this is me after cat -n dod.sh ... ). The fact is that I have Linux avp-ubu1 4.4.0-43-generic #63-Ubuntu SMP Wed Oct 12 13:48:03 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux in Linux avp-ubu1 4.4.0-43-generic #63-Ubuntu SMP Wed Oct 12 13:48:03 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux this script works , of course, ending with the message ./tt.sh: line 36: /home/avp/hashcode/hl_linux: No such file or directory . Try inserting the following code into the line after #!/bin/bash [ A == A ] && echo It works! && exit [ A == A ] && echo It works! && exit and write what happened - avp

3 answers 3

To begin with: do not work from the root. Create a user. It will be right.
Then look at what lines the error gives. If you look closely, then these are all lines with if.
Accordingly, the bash does not like the comparison:

 if [ "$UNAME" == "Darwin" ] 

and similar. As far as I know, comparisons occur in bash:

 if [ $env = "string" ] 

Read here: https://www.opennet.ru/docs/RUS/bash_scripting_guide/c2171.html

If it does not help, try on the advice of Alexander Blinov - try to specify when you launch

 $ bash script_name.sh 
  • Only through bash (specifically this script is due to cd here: GAMEROOT=$(cd "${0%/*}" && echo $PWD) ) should be launched with an indication of the table of contents, for example bash ./script-name.sh - avp

Vanguey, of course ... But, probably, you run the script #sh ./dod.sh

Just run #./dod.sh or #bash ./dod.sh

Now, perhaps, the stupid question will be ... Did you remember to do chmod?

 chmod +x dod.sh chmod +x hl.sh chmod +x hl_linux 
  • Does not help. Nothing happens. - GeenTeen
  • Updated the answer 15 characters - Alexandr Blinov

The script code in the question is absolutely functional (in the bash interpreter).

Carefully check (for example, with the command cat -n dod.sh | grep 16 | hd (or something similar to your choice)) the characters around [ in the lines for which you are swearing, are these really spaces.

It is also possible (judging by the characteristic diagnostics - [: Linux: unexpected operator ) that you /bin/bash either is a reference to dash , or is simply replaced by this command, which issues exactly such diagnostics for an unknown operation == .