Léo*_* 준영 0 unix variables bash
如何设置适用于所有地方的变量?我的.bashrc有:
Questions='/Users/User/Stackoverflow/Questions'
Address='My address'
Run Code Online (Sandbox Code Playgroud)
我的档案有:
$Questions
$Addres
Run Code Online (Sandbox Code Playgroud)
Shell中的命令"$ cat my_file"打印"$ Questions"和"$ Address",而不是"/ Users/User/Stackoverflow/Questions"和"My address".我想要变量的其他地方是电子邮件和浏览器.但我不能让他们工作.
如何让我的变量在每个程序中都有效?
cat不解释变量.它只是逐字节地打印出文件的内容.
如果您希望能够打印出变量的值my_file,我建议将其更改为读取
echo "$Questions"
echo "$Address"
Run Code Online (Sandbox Code Playgroud)
然后你就可以"获取"它(有点像在当前shell环境中运行它)
$ source my_file
Run Code Online (Sandbox Code Playgroud)
要么
$ . my_file
Run Code Online (Sandbox Code Playgroud)
您可能还必须使用exportin .bashrc,如下所示:
export Questions='/Users/User/Stackoverflow/Questions'
export Address='My address'
Run Code Online (Sandbox Code Playgroud)