csh

in cshell: How to I set a variable to the command line output?

折月煮酒 提交于 2020-01-06 02:27:07
问题 I do want to start a batch job that generates a jobid as output. How can I save the jobid as environmental variable and reuse it in the cshell script? Thanks and best wishes, Rollz 回答1: Use backticks to substitute the output of a command into the command line. To set an ordinary variable: set varname = `start_batch_job` To set an environment variable: setenv varname `start_batch_job` You should generally avoid scripting in C-shell, it has lots of problems that make it poor as a scripting

Why are operators right associative in CShell that are left associative in C?

情到浓时终转凉″ 提交于 2020-01-05 08:36:14
问题 Following up from my previous question, why is CShell so different from C? 4 - 3 + 1 = 2 in C. 4 - 3 + 1 = 0 in CShell. Any ideas? 回答1: Generally the traditional notation is left to right (left associative) in human papers. So for humans (which used this notation long before c, csh or even any notion of computers): 4 - 3 + 1 = (4 - 3) + 1 = 1 + 1 = 2 Why? I guess that the best answer is because. It's the same as with driving left or right side of road. It really doesn't matter which side as

Convert n number of rows to columns repeatedly using awk

跟風遠走 提交于 2020-01-05 08:32:28
问题 My data is a large text file that consists of 12 rows repeating. It looks something like this: { 1 2 3 4 5 6 7 8 9 10 } repeating over and over. I want to turn every 12 rows into columns. so the data would look like this: { 1 2 3 4 5 6 7 8 9 10 } { 1 2 3 4 5 6 7 8 9 10 } { 1 2 3 4 5 6 7 8 9 10 } I have found some examples of how to convert all the rows to columns using awk: awk '{printf("%s ", $0)}' , but no examples of how to convert every 12 rows into columns and then repeat the process.

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,

if-else on arguments in npm run script

荒凉一梦 提交于 2020-01-04 02:50:32
问题 I would like to call different other scripts, depending on whether a paramter is given or not: "paramtest": "if [ -z $1 ]; then echo Foo $1; else echo Bar; fi", npm run paramtest should give "Bar". npm run paramtest -- whatever should give "Foo whatever". However in practice I only get: (The parameter is added to the whole line, not 'passed in') > if [ -z $1 ]; then echo Foo; else echo Bar; fi "whatever sh: 1: Syntax error: word unexpected What can I do better? Essentially I am after running

How to use for loops in command prompt in csh shell — looking for decent one liners

拜拜、爱过 提交于 2020-01-03 18:54:36
问题 coming from bash shell, I missed on an easy rolling of loops (for i in (...); do ... done;) Would you post typical one-liners of loops in cshell? ONE LINERS PLEASE, and not multiple-lines thx 回答1: Wow, I haven't written a csh script in years. But Bill Joy did write it himself, I suppose it's worth some nostalgia effort... set t=(*) foreach i ($t) echo $i >> /tmp/z end or just foreach i (*) This loop structure works well with a built-in concept that csh has of a word list . This is sort-of

bash vs csh vs others - which is better for application maintenance? [duplicate]

匆匆过客 提交于 2019-12-31 21:43:12
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: What Linux shell should I use? I am starting to get proficient in a Linux environment and i'm trying to pick a weapon of choice in terms of command shell scripting (as i'm still a big n00b at this) that will help me (and others) manage, test and administer a set of server side applications running on a *NIX environment. My question is: What is(are) the preferred command shell(s) out there when the following

Difference between source and ./ execution of linux scripts

ε祈祈猫儿з 提交于 2019-12-31 03:17:06
问题 csh: set a=0 echo "a is $a" when i do ./my_script.csh output is: a is when i do source my_script.csh output is: a is 0 Why is it so . As i know that ./ execution uses new shell. 回答1: check if variable "a" is set in your current shell: set | grep '^a=' Remember that once you source script to your current shell, all it's global variables are there until unset or you exit the current shell. You may want to start a new shell, source the script, end exit shell to perform valid tests. I don't know

How to replace a path with another path in sed?

强颜欢笑 提交于 2019-12-28 02:57:33
问题 I have a csh script (although I can change languages if it has any relevance) where I have to: sed s/AAA/BBB/ file The problem is that AAA and BBB are paths, and so contain '/'. AAA is fixed, so I can say: sed s/\\\/A\\\/A\\\A/BBB/ file However, BBB is based on variables, including $PWD. How do I escape the '/' in $PWD? OR is there some other way I should be doing this entirely? 回答1: sed can use any separator instead of / in the s command. Just use something that is not encountered in your

A newly defined alias within another alias, the first excution will fail

自古美人都是妖i 提交于 2019-12-25 02:01:46
问题 If we define and use an alias B within another alias A, the first time execution of A will fail. For example, alias A='alias B="which ls"; B;' The first time excution would look like (in bash) bash: B: command not found The example above is a simplified construction. in practice, we might meet such usage implicitly. The reason might be: when we execute the alias A, all expansions are carried out before execution, but B is undefined when we execute A for the first time. So is there a way to