注册 登录
编程论坛 Linux教室

shell脚本中source问题

suxiaochen 发布于 2010-04-26 19:46, 1155 次点击
shell脚本(test.sh)如下:

#!/bin/sh

echo "export monitor=1" >> /etc/profile
source /etc/profile

调用后(./test.sh),执行echo $monitor,没有输出任何值

手动source /etc/profile后,再次执行echo $monitor,输出了预期的值

可见脚本中的source /etc/profile没有成功,请问这个应该怎么解决?
4 回复
#2
vfdff2010-05-16 00:31
source 干什么的?
#3
oscillator2010-11-16 09:05
以下是引用vfdff在2010-5-16 00:31:05的发言:

source 干什么的?
我的理解是要执行或者加载某文件的时候,就source一下。
#4
viky20032011-01-19 20:46
你看看export -p | grep moniter 看suorce是否成功。
#5
vfdff2011-03-08 23:48
source /etc/profile后使用echo $?可以查看是否成功
1