我有一个名为的文件raw_info
,我想要一个变量指向该文件,以便当我在脚本中键入命令时,它会知道查找raw_info
.对于此作业,我被要求在脚本顶部将变量定义starting_info
为具有以下值raw_info
我在脚本的开头尝试过:
#Homework Week X
name=First\ Last
echo $name
date
starting_info=raw_info
cut -f3 -d, starting_info > first
cut -f2 -d, starting_info > last
cut -f1 -d, starting_info > id
#(pretend the rest of my script is here)
但我收到错误消息:
cut: starting_info: No such file or directory
答案1
解决方案
#!/bin/bash
#Homework Week X
name="First Last"
echo "$name" # always quote variables
date
starting_info=raw_info # now starting_info is a variable
# then you need $ sigil to call it:
cut -f3 -d, "$starting_info" > first
cut -f2 -d, "$starting_info" > last
cut -f1 -d, "$starting_info" > id
#(pretend the rest of my script is here)