我正在尝试做类似的事情。
#!/bin/bash
readonly bkp_path="x01/trdprod"
bkp_location=" "
bkp_dir=" "
function crt_bkp_dir(){
bkp_dir=$(read user_input) ## assume inserted value is test
bkp_location="$bkp_path/$bkp_dir"
}
function main(){
crt_bkp_dir
echo $bkp_location
}
main
我需要获得输出
x01/trdprod/test
。相反,我得到一个空的输出。有人可以告诉我我做错了什么以及如何做正确的事情吗?
var1=$(read var2)
将 var1
设置为 read var2
的 output,通常什么都没有(即
var1
最终设置为空白)。
尝试以下操作:
# replace this:
bkp_dir=$(read user_input)
# with this:
read bkp_dir