tcsh

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

Tcsh run command if command was run

家住魔仙堡 提交于 2019-12-31 03:11:49
问题 I'm not really familiar with TCSH I would like run a command2 if a command1 was entered in the shell, something like this: if command1 then echo "Command succeeded" command2 else echo "Command failed" fi I tried this code but it doesn't work. Step two would be to read and print in a file a part some variable that command1 changed (making a kind of history only for some variables). 回答1: You can use $? to get exit code from last command. #!/bin/tcsh # command below can fail or succeed command1

Remove symbolic links only from a folder in tcsh [closed]

强颜欢笑 提交于 2019-12-25 18:37:13
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 12 months ago . I need to remove a large number of symbolic links from a folder that has other files which I don't want to remove. Is there any easy way to remove only symbolic links? 回答1: You can use the find(1) command find . -maxdepth 1 -type l -exec rm {} \; -maxdepth 1 is for only scanning current directory. -type l is

sed command failure with curly braces and double quotes values

烂漫一生 提交于 2019-12-25 08:43:19
问题 I have a file with the following content (ABC) I create an env variable with the following command setenv ABC {"a":{"b":"http://c","d":"http://e"}} Then I run the sed command sed 's|(ABC)|('"$ABC"')|' myFile This returns with this a:b:http://c a:d:http://e It shuld actually return this {"a":{"b":"http://c","d":"http://e"} Any ideas on what I am missing 回答1: Since braces and double quotes are metacharacters in C shell, you have to either escape them with backslash, like this: setenv ABC \{\"a\

Changing a directory of the parent shell [duplicate]

余生颓废 提交于 2019-12-25 00:01:44
问题 This question already has answers here : Why doesn't “cd” work in a shell script? (29 answers) Closed last year . I 'm wondering of any mechanism that one could use to change the directory of a parent shell from sub-shell. For ex., I 'm running the script "settings.sh" in my $HOME. My $HOME has a directory $HOME/TEST/run. If my "settings.sh" scripts is as below #!/bin/bash # some shell related code # some shell related code cd $HOME/TEST/run exit 0 I execute the above script at command prompt

How do I correctly use getopt in a cshell script?

随声附和 提交于 2019-12-24 12:34:51
问题 Problem I am trying to make a chshell script that takes in user input from several options. Inspired by this bash example, I tried to construct a while loop and switch case statement pattern around the getopt command. After several iterations I have tried to interpret this example from IBM: set argv=`getopt :a:b:c:d:e: $*` if ($? != 0) then exit 1 endif while ({ ` $1 != --` }) switch ($1) case[-a]: yada breaksw case[-b]: yada breaksw case[-c]: yada breaksw case[-d]: yada breaksw case[-e]:

How to move the cursor by word in command line of tcsh

做~自己de王妃 提交于 2019-12-24 10:58:45
问题 I am stucked by this for a long time. How can I move the cursor in the command line of tcsh, as did by ctrl + arrow in vim editor, ipython shell, firefox, word etc. All these above can do this nicely, excetp tcsh, which is really frustrating. 回答1: Try Esc b and Esc f . For future reference, non-programming-related questions like these may be more appropriate at SuperUser. 回答2: tcsh has key bindings to mimic VI-style editing commands. Just put this in your ~/.cshrc file: > bindkey -v You can

Makefile Rules and If Statements — How?

こ雲淡風輕ζ 提交于 2019-12-23 10:17:23
问题 I'm new to Makefiles so please bear with me. I need to modify a Makefile so some rules call different utilities depending on a variable. Right now, a rule looks like: ci: [shell syntax for tool (A)] But now I need ci to have a different syntax depending on the variable. So I define a global variable at the top of the file: TOOL = toolA or TOOL = toolB Ideally what I'd like is something like this, but obviously it doesn't work : ifeq ($TOOL, toolA) ci: [syntax for tool (A)] else ci: [syntax

Exit tcsh script if error

我的梦境 提交于 2019-12-23 07:16:33
问题 I am tryin to write a tcsh script. I need the script exit if any of its commands fails. In shell I use set -e but I don't know its equivalent in tcsh #!/usr/bin/env tcsh set NAME=aaaa set VERSION=6.1 #set -e equivalent #do somthing Thanks 回答1: In (t)csh, set is used to define a variable; set foo = bar will assign the value bar to the variable foo (like foo=bar does in Bourne shell scripting). In any case, from tcsh(1) : Argument list processing If the first argument (argument 0) to the shell