LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 793|回复: 7

为什么我的写的TCSH,没有办法执行CD命令?

[复制链接]
发表于 2004-10-12 16:37:47 | 显示全部楼层 |阅读模式
下面是我的代码,但是执行后就是没有办法改变路径,请大家给指点一下。

谢谢

#!/usr/bin/tcsh

if ( $1"NULL" == "NULL" ) then
  echo -n "lease enter the project name:"
  set PROJECTNAME=$<
else
  set PROJECTNAME=$1
endif

echo $PROJECTNAME

switch ($PROJECTNAME)
  case genie_snap:
    cd dp203
  breaksw
  default:
    cd /
endsw
 楼主| 发表于 2004-10-15 11:24:08 | 显示全部楼层
怎么这个问题没有人帮忙? 是有点太简单了吗?
发表于 2004-10-15 11:44:26 | 显示全部楼层
你在执行时确实进了那个目录,但由于你的脚本是在子shell里运行,脚本退出后就又回到了执行脚本前的工作目录,你可以在脚本里cd后加入pwd测试一下脚本里是否已经改变了当前工作目录。
 楼主| 发表于 2004-11-1 13:31:01 | 显示全部楼层
How to let me stay at that directory after exit the script?
发表于 2004-11-1 23:04:03 | 显示全部楼层
用source foo.sh 来执行你的脚本。
 楼主| 发表于 2004-11-2 09:31:34 | 显示全部楼层
Thanks.

Now I hope to know why it will have this difference between run the script directly and source it.
发表于 2004-11-2 14:15:38 | 显示全部楼层
When you run your script directly, in fact , you run it in a new subshell.
When you run your script by source it, it runs in the current shell, that's the difference.
 楼主| 发表于 2004-11-2 15:40:09 | 显示全部楼层
Ok, thanks.
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表