Linux Bash脚本文件作为输入
我正在尝试将一个文件作为shell脚本的输入: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
#!/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"