繁体   English   中英

Bash shell 脚本文件存在

[英]Bash shell script file exists

嗨,我的 bash 脚本说传递给它的第一个参数不作为文件存在,但确实存在。 请问我做错了什么?

运行脚本并从 linux 传入两个参数: ./concantenatefile.sh file1.txt file2.txt

#!/bin/bash

file1="$1"

if [ -e file1 ]
then    
    echo "The file $file1 exists"
else    
    echo "The file $file1 doesn't exist"
fi

它说The file file1.txt doesn't exist但是在当前工作目录中有一个名为file1.txt的文件。

您当前没有取消引用 file1 变量在行中

if [ -e file1 ]

您需要添加一个 $ 来取消引用变量并访问其内容

if [ -e $file1 ]

暂无
暂无

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

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