免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2924 | 回复: 4
打印 上一主题 下一主题

[文件目录] bash里面调用csh程序,cd不起作用的解决方案 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2018-09-19 01:06 |只看该作者 |倒序浏览
大家好,程序的目的是用户输入设定命定,然后cd到一个路径,source一个文件。

文件名是test.sh,存放路径是/home,内容如下:

#!/bin/sh
if [[ $1 == "" ]];then
echo "no input"
elif [[$1 != ""]];then
cd /tmp/1 && source /tmp/1/.cshrc


现在在/home下执行:./test.sh x
结果程序执行完后不会cd到/tmp/1下,而且source也没有成功,因为推出了父程序的原因吧。

现在就是想用./test.sh x实现程序执行完后能cd到那个路径,而且source那个文件。网上的教程都是说直接source test.sh或者. ./test.sh,但是这不是我要的,不知道有没有人有办法做到?非常感谢。

论坛徽章:
0
2 [报告]
发表于 2018-09-19 01:11 |只看该作者
就是说本身test.sh执行完后,程序能跳出来,再执行以下cd这个命令,感觉才有可能

论坛徽章:
0
3 [报告]
发表于 2018-09-19 14:42 |只看该作者
When you run test.sh,  test.sh is executed in subshell

That's why your current directory and environment does not change after running test.sh

Please try to run test.sh by and tell us the results:

exec test.sh

论坛徽章:
0
4 [报告]
发表于 2018-09-19 21:47 |只看该作者
回复 3# csccyab


Sorry, I referred that your method is not the solution for me in my post.
I just want to use the command to cd to the path but not with source.
I know some one did this, but I don't know how.

论坛徽章:
0
5 [报告]
发表于 2018-09-19 21:48 |只看该作者
回复 3# csccyab

不好意思,我不想通过source解决这个问题,因为我这个程序设计的初衷就是要用命令,例如sw实现自动跳转。
我知道有人成功了,不是通过source,而是直接执行。

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP