: command not foundop/dominio.sh: line 2:

a 夏天 提交于 2019-12-25 02:41:12

问题


I'm writing shell scripting for Mac. Here's my script:

echo "Bienvenido";
/Applications/sdk/platform-tools/adb devices;
sudo /Applications/sdk/platform-tools/adb  shell input text 'sp.soporte@gmail.com';

It realize the correct operation, but here is the output :

$ /Users/julien/Desktop/dominio.sh 
Bienvenido
: command not foundop/dominio.sh: line 1: 
List of devices attached 
4790057be1803096    device

: command not foundop/dominio.sh: line 2: 
: command not foundop/dominio.sh: line 3: 

julien$

If I erase the ; it's not working any more. How should I do????


回答1:


I think you have Windows-style line endings in your script.

Unix-like systems, including MacOS, use a single LF character to terminate a line; Windows uses a CR-LF pair.

A Windows-style text file looks, on a Unix-like system, like ordinary text with an extra CR character at the end of each line.

Since you have a semicolon at the end of each line, this line:

echo "Bienvenido";

appears to the shell as two commands: echo "Bienvenido" and the CR character (which could actually be a command name if it existed). Note that the echo command was executed.

The shell prints an error message, something like:

/path/to/script: 1: CR: command not found

except that it prints the actual CR (carriage return) character, which moves the cursor to the beginning of the current line, overwriting part of the error message.

Translate your script to use Unix-style line endings. You can use dos2unix for this if you have it. (Read the man page; unlike most filter programs, it overwrites its input file by default.)

Incidentally, you don't need a semicolon on the end of each line of a shell script. Semicolons are needed only when you have multiple commands on one line.

Also, you should probably have a "shebang" as the first line of your script, either #!/bin/sh or #!/bin/bash (use the latter if your script uses bash-specific features).



来源:https://stackoverflow.com/questions/21889410/command-not-foundop-dominio-sh-line-2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!