简体   繁体   English

Shell脚本变量结构

[英]Shell script Variable Structure

How can I create a variable with a file name format like : FileName pattern: SnapshotIR__somenumber.csv 如何创建具有以下文件名格式的变量:FileName模式:SnapshotIR__somenumber.csv

I tried something like : 我尝试了类似的东西:

TODAY=$(date +"%m%d%Y")    
SNAPSHOT = $(SnapshotIR$TODAY*.csv)

I get error like : 我收到如下错误:

test.sh: line 2: SnapshotIR02122013_2239.csv: command not found
test.sh: line 2: SNAPSHOT: command not found

so, when I want to use with if 所以,当我想与if

if [ -f SnapshotIR$TODAY*.csv]  -> works 
if [ -f ${SNAPSHOT} ]           -> does not work (I get the above error)
SNAPSHOT=SnapshotIR${TODAY}\*.csv

when you give $(.....) it says shell to execute the command within the braces. 当您给出$(.....)时,它说外壳程序在花括号内执行命令。 i guess you are just forming the file name. 我猜你只是在形成文件名。

also remove the spaces: 还要删除空格:

SNAPSHOT<space>=<space>

i would also like to add wildcard "*" will not work for -f flag. 我还想添加通配符“ *”不适用于-f标志。

for file in $SNAPSHOT
do
        if [ -f "$file" ]
        then
                FOUND="$file"
                break
        fi
done

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

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