change working directory from csh script

霸气de小男生 提交于 2021-01-28 21:43:40

问题


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

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.

I now want to combine that to a csh script or some alias in my .cshrc.


My atempt so far:

#/bin/csh

set jobfile = `find ~ -name $argv[1].out`
set jobdir = `dirname $jobfile`
set scrdir = `cat $jobdir/.scrdir`
echo $scrdir

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?


I would also be grateful for any advice to refine the question / -title.


回答1:


Since there are no shell functions in csh, the only solution I found is to call the script with source.

The script:

#/bin/csh

set jobfile = `find ~ -name $argv[1].out`
set jobdir = `dirname $jobfile`
set scrdir = `cat $jobdir/.scrdir`
cd $scrdir

To call the script:

source myscript.sh


来源:https://stackoverflow.com/questions/28135356/change-working-directory-from-csh-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!