Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux Bash脚本文件作为输入_Linux_Shell - Fatal编程技术网

Linux Bash脚本文件作为输入

Linux Bash脚本文件作为输入,linux,shell,Linux,Shell,我正在尝试将一个文件作为shell脚本的输入: #!/bin/bash file ="$1" externalprogram "$file" echo 'unixcommand file ' 我试图给我的文件路径,但它总是说 无法打开“=/home/username/documents/file”(没有这样的文件或目录) 我的路径是/home/username/Documents/file 我在终端中执行此操作:./myscript.sh/home/u

我正在尝试将一个文件作为shell脚本的输入:

#!/bin/bash
file ="$1"
externalprogram "$file"
echo 'unixcommand file ' 
我试图给我的文件路径,但它总是说

无法打开“=/home/username/documents/file”(没有这样的文件或目录)

我的路径是/home/username/Documents/file

我在终端中执行此操作:./myscript.sh/home/username/Documents/file

有人能帮我吗?

当你说

file=“$1”

在“file”后面有一个空格,您正在运行一个名为
file
的程序,其中
=$1
作为参数。实际上可能有一个名为
file
的实用程序。如果要将
$1
分配给名为
file
的变量,则不需要空格:


file=“$1”

第二行中的=前面不应该有空格。 file=$1应该足够好了。

检查您的代码:

 ^-- SC1068: Don't put spaces around the = in assignments (or
 quote to make it literal).
您可以阅读有关SC1068案例的更多信息


我制作这个代码片段是为了演示,我传递了一个路径,它会在vscode中打开文件

没有关于它的“可能”<代码>文件是一个。可以合理地假设这里调用的是
文件
,但这是一个假设。基于容器的Linux映像可能不包括
文件
,或者实际上不包括任何“标准”实用程序。
#!/bin/bash

file=$1

code $file

echo "aberto o arquivo ${file} no vscode"