2014-02-18 153 views
1

是写作shell脚本中的新变量。当我每次执行下面的程序中,我得到“$ userInput1 = /家庭/ XY-X/DEST1:没有这样的文件或目录无法将变量设置为路径

fun1() 
{ 
    . 
    . 
    $2=$userInputPath'/*' #$userInputPath holds a path like /home/xyx/dest1 
    . 
    . 
} 

正在使用Bourne shell和调用诸如以下方式的作用 -

fun1 $input1 userInput1 

并在调用该函数后,如果我echo $ userInput1它不打印任何东西。需要提及的是/ home/xyx/dest1路径是有效的。

回答

0

那么通常你会使用declare,但它是在 功能。所以如果你想访问userInput1以外的 你需要做的功能

fun1() { 
    read $2 <<< "$userInputPath/*" 
}