문제

I'm currently trying to rewrite some tcsh shell scripts with Python.

One thing that I just saw is

set WORK = "/dev/shm"

if ( $?WORK ) then
    if ( $WORK == "" ) then
    set WORK = "/tmp"
    endif
else
    set WORK = "/tmp"
endif

What does this do?

My first thought (before reading this related question) was that it checks if the variable $WORK was set. But this makes not so much sense, because it was set two lines before. Also, this seems not to be related to "error codes". Can you tell me what this part is supposed to do?

도움이 되었습니까?

해결책

On the first look, I would say it checks if directory specified in WORK exists. If it does, it checks if "" and sets it to "/tmp" if it is. Also, if it does not exist sets it to "/tmp".

Looks like some sort of working directory variable. Working directory can be "" (current directory).

So basically this script exists if /dev/shm exists, because user is probably supposed to enter his own directory in WORK.

Let me know what you think.

다른 팁

At no point is there a test for if a directory actually exists.

set WORK = "/dev/shm"           # sets the WORK var to /dev/shm

if ( $?WORK ) then              # tests if the WORK var is set
    if ( $WORK == "" ) then     # WORK is set, test if it is set to ""
        set WORK = "/tmp"       # empty WORK var is set to /tmp
    endif
else
    set WORK = "/tmp"           # WORK was not set, set to /tmp
endif

In other words, the entire "if" block of code is useless.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top