从csh脚本更改工作目录 [英] change working directory from csh script
问题描述
我想查找一些正在运行的进程的数据,实际上我正在搜索暂存目录中的相应作业ID.我设法通过以下命令手动执行此操作(假设job-ID为12345):
I want to lookup some data of running processes, actually I'm searching for the scratch directory to a corresponding job-ID. I managed to do that manually by the following commands (assuming the job-ID is 12345):
find ~ -name '12345.out'
这将根据作业查找输出文件:
This finds the output file according to the job:
/home/username/somefolder/12345.out
临时目录被写入该文件夹中名为.scrdir的文件中,因此
The scratch directory is written to a file named .scrdir in that folder, so
cd | cat /home/username/somefolder/.scrdir
把我带到我想要的地方.
brings me where I want.
我现在想将其组合到我的 .cshrc 中的csh脚本或某些别名.
I now want to combine that to a csh script or some alias in my .cshrc.
到目前为止,我的无能
#/bin/csh
set jobfile = `find ~ -name $argv[1].out`
set jobdir = `dirname $jobfile`
set scrdir = `cat $jobdir/.scrdir`
echo $scrdir
其中第一个参数值是作业ID,例如12345该脚本可打印正确的暂存目录,但我希望它在调用脚本后将我的实际工作目录更改为暂存目录.如何在csh脚本中更改工作目录?
where the first argument value is a job-ID, 12345 e.g. This script prints the right scratch directory but I want it to change my actual working directory to the scratch directory after I've called the script. How can I change the working directory from within a csh script?
我也将感谢您提出任何改进问题/-title的建议.
I would also be grateful for any advice to refine the question / -title.
推荐答案
由于csh中没有shell函数,因此我发现的唯一解决方案是使用 source
调用脚本.
Since there are no shell functions in csh, the only solution I found is to call the script with source
.
脚本:
#/bin/csh
set jobfile = `find ~ -name $argv[1].out`
set jobdir = `dirname $jobfile`
set scrdir = `cat $jobdir/.scrdir`
cd $scrdir
调用脚本:
source myscript.sh
这篇关于从csh脚本更改工作目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!