tcsh

Do we have short circuit logical operators in C shell script?

血红的双手。 提交于 2021-02-19 07:23:12
问题 I thought C shell script will behave like C and use short circuit evaluation for logical operators. if ((! -e $cache ) || ("`find $monitor -newer $cache`" != "")) then ... endif But in the if statement, even if the first condition is true, the second is checked giving me errors. Do we have a short circuit logical OR in C shell script? 回答1: Usually, && and || are short-circut. Consider something like this: $ false && echo foo $ true || echo foo In both cases, foo won't be put out. But, AFAIK

Using name of BASH script as input argument

本秂侑毒 提交于 2021-01-29 09:47:11
问题 I have a large number of .pbs files that I want to submit to a remote cluster. I want to be able to name the .pbs file something like "param1_123_param2_45.pbs", and then feed them into the ARGS for a Julia code. Below is an example .pbs of what I'm trying to do: 1 #!/bin/tcsh 2 #PBS -l mem=10gb,nodes=1:ppn=2,walltime=1:00:00 3 #PBS -j oe 4 #PBS -o ./log/julia.${PBS_JOBID}.out 5 #PBS -t 1-3 6 7 module load julia/1.5.1 python/3.8.1 8 9 cd path/to/file 10 11 julia Example.jl 123 45 Except 123 &

How do I get `__FILE__` when sourcing a csh script

a 夏天 提交于 2021-01-26 17:59:30
问题 I have a script that is used to set some env vars in the calling csh shell. Some of those variables depend on the location of the script. If the file is a proper csh script, I can use $0 to access __FILE__ but if I run the script using source, it just tells me csh or tcsh. Since I'm using this to set vars in the parent shell, I have to use source. What to do? 回答1: If you access $_ on the first line of the file, it will contain the name of the file if it's sourced. If it's run directly then $0

tcsh alias with if-then-else condition

痞子三分冷 提交于 2020-06-04 03:12:10
问题 I am trying to have an alias with if-then-else condition on a command result. the alias will get a file pattern if there is just one file it will open the file if there is more or less then 1 files - it will indicate with a message. the alias I have tried is: alias atest 'if \("ls \!:1" > 0 \) "nedit ls \!:1" else "echo cant open the file" ' 回答1: You can't do this with an alias. An alias can only expand into a one-line command, but if requires multiple lines. Instead, use a shell script. The

How do I launch an editor from a shell script?

点点圈 提交于 2020-01-22 06:57:38
问题 I would like my tcsh script to launch an editor (e.g., vi, emacs): #!/bin/tcsh vi my_file This starts up vi with my_file but first displays a warning "Vim: Warning: Output is not to a terminal" and my keystrokes don't appear on the screen. After I kill vi, my terminal window is messed up (no newlines), requiring a "reset". I tried "emacs -nw", "xemacs -nw", and pico with similar results. "xemacs" works but launches a separate window. I want to reuse the same terminal window. Is there a way to

Embedding commands in strings

早过忘川 提交于 2020-01-16 05:25:31
问题 Consider the following: #!/bin/tcsh set thing = 'marker:echo "quoted argument"' set a = `echo "$thing" | sed 's/\([^:]*\):\(.*\)/\1/'` set b = `echo "$thing" | sed 's/\([^:]*\):\(.*\)/\2/'` echo $a echo $b $b echo "quoted argument" This gives marker echo "quoted argument" "quoted argument" quoted argument If $b is echo "quoted argument" , why does evaluating $b give a different result from echo "quoted argument" ? Since I know tcsh is awful (but it's what I have to use for work), here is the

Escaping double quotes with tcsh alias

江枫思渺然 提交于 2020-01-09 11:39:10
问题 I'm trying to run the following commands: replace -x "must " A2input.txt replace -x " a" -f -s ## A2input.txt replace -x to -s ## -a A2input.txt replace -x faith -f "unequivocal" A2input.txt And it'd be nice if I could just alias it to something short and simple like "a", "b", "c", "d", etc... However, some of those arguments have a quote, which is messing up the alias. Does anyone know how to actually escape the double quotes? I've tried things like '\"' and \" but nothing seems to work. I'm

Replacing a fixed part of PWD in a tcsh prompt

别等时光非礼了梦想. 提交于 2020-01-04 06:30:43
问题 My prompt is currently displayed like here: [Aug-27 14:36] /x/y/z/w/u/v/dir1/dir2/dir3> What I would like to do is replace the constant partial-path of the current working directory /x/y/z/w/u/v with $WORK so eventually what will be displayed is [Aug-27 14:36] $WORK/dir1/dir2/dir3> /x/y/z/w/t/u is always the same path from which I usually do my work and for which I have a local variable $WORK set (very similar to the home ~ idea). A straight-forward solution will be most-welcomed as I really

Replacing a fixed part of PWD in a tcsh prompt

偶尔善良 提交于 2020-01-04 06:30:12
问题 My prompt is currently displayed like here: [Aug-27 14:36] /x/y/z/w/u/v/dir1/dir2/dir3> What I would like to do is replace the constant partial-path of the current working directory /x/y/z/w/u/v with $WORK so eventually what will be displayed is [Aug-27 14:36] $WORK/dir1/dir2/dir3> /x/y/z/w/t/u is always the same path from which I usually do my work and for which I have a local variable $WORK set (very similar to the home ~ idea). A straight-forward solution will be most-welcomed as I really

Setting a part of a PWD as a prompt and keeping a variable updated

随声附和 提交于 2020-01-04 02:56:10
问题 I'm using tcsh, and I'm trying to set a part of the PWD to appear always in the prompt (so I will always know in which "parent" directory I am). I managed to extract the needed part of the prompt in the following way, and it works fine (I call it MyTreePath ): set MyTreePath=`echo $PWD | awk '{... print whichTree}'` I've added the code above to my .tcshrc and I've added %$MyTreePath to my set prompt line in .tcshrc . The problem is that once the shell is opened, the MyTreePath doesn't change,