简体   繁体   English

在bash脚本中定义“ PATH”变量时出现scp错误

[英]scp error when defining a “PATH” variable in a bash script

So this is my script 这是我的剧本

#!/bin/bash
PATH=/SomeFolder/file2.txt;     
scp -3 user@server1:/SomeFolder/file.txt user@server2:$PATH;

I get this error 我得到这个错误

main.sh: line 3: scp: command not found main.sh:第3行:scp:找不到命令

If I put /SomeFolder/file2.txt in place of of "$PATH" it still doesn't work - same error. 如果我将/SomeFolder/file2.txt代替"$PATH"它仍然不起作用-相同的错误。 It's only after I remove entire second line ( PATH definition) does it work. 只有删除了第二行( PATH定义)后,它才起作用。

I simplified my script, the PATH is defined by executing a script inside another server but that doesn't matter. 我简化了脚本,通过在另一台服务器内执行脚本来定义PATH ,但这没关系。 I tested it like what you see and I concluded that the error is due to PATH being defined in the first place. 我按照您所看到的进行了测试,并得出结论,该错误是由于首先定义了PATH而引起的。

It is happening because PATH is a system variable that defines directories where the programs and scripts should be looked for. 之所以发生这种情况是因为PATH是一个系统变量,它定义了应在其中查找程序和脚本的目录。 You can view its value by executing echo $PATH . 您可以通过执行echo $PATH查看其值。 In your script you are setting PATH to /SomeFolder/file2.txt so the program scp that is usually in /usr/bin/ can't be found. 在脚本中,您将PATH设置为/SomeFolder/file2.txt因此/SomeFolder/file2.txt通常在/usr/bin/的程序scp Just change the name of variable PATH in your script to something else. 只需将脚本中变量PATH的名称更改为其他名称即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM