csh

How do I split a String in CSH?

扶醉桌前 提交于 2019-12-08 17:11:53
问题 For example, I want to split "one,two,three" with comma as delimiter and use a loop to process the resulted three substring separately. 回答1: For example: set s = "one,two,three" set words = `echo $s:q | sed 's/,/ /g'` foreach word ($words:q) echo $word:q end But consider whether csh is the right tool for whatever job you're doing: http://www.bmsc.washington.edu/people/merritt/text/cshbad.txt 回答2: A simpler solution than the current one presented involves using the built-in substitution

csh idioms to check for environment variable existence?

∥☆過路亽.° 提交于 2019-12-08 14:28:00
问题 I've got a few csh scripts where I need to check that certain environment variables are set before I start doing stuff, so I do this sort of thing: if ! $?STATE then echo "Need to set STATE" exit 1 endif if ! $?DEST then echo "Need to set DEST" exit 1 endif which is a lot of typing. Is there a more elegant idiom for checking whether or not an environment variable is already set? Notes: This question is quite similar, but specifically asks about solutions in bash. I'm not looking for people to

UNIX\LINUX: How to add a directory text to each line inside a file?

与世无争的帅哥 提交于 2019-12-08 13:54:23
问题 UNIX\LINUX: How to add a directory text to each line inside a file? NOTE: I am just using shell(CMD TOOL OF LINUX REDHAT EPIC) no other... You see I have many log files(.txt.gz) and I was able to open all of them just by using: foreach i (./*/*dumpfiles.txt.gz_*) > foreach? zcat $i > foreach? grep "-e" $i > foreach? END Meaning I am going through all those folders finding a file dumpfiles.txt.gz_ The the output is like: 0x4899252 move x -999 0x4899231 move y -0 0x4899222 find scribe 0x4899231

stderr redirection methods

a 夏天 提交于 2019-12-08 12:39:50
问题 I am running tcsh/csh shell on my machine. lately i have realized my stderr file redirection is not working. Please find the terminal logs as below: >echo b c >>& log >cat log b c >echo $a b c >>& log a: Undefined variable. >cat log b c I have never faced such issues, hence not sure how to debug or troubleshoot. Please advice! An alterate method of redirection is using tee. While I use >& or >>& , i am altogether blocking any output to be displayed on terminal. Is there a way I can do both,

how to read xml file in linux

巧了我就是萌 提交于 2019-12-08 12:09:06
问题 I have one xml file as below, I need "en" using some unix command. <void method="put"> <string>LANGUAGE</string> <string>en</string> </void> using below command (got from some link in google), sed -n '/string/{s/.*<string>//;s/<\/string.*//;p;}' Locale.xml I am getting output as LANGUAGE en so I used sed -n '/string/{s/.*<string>//;s/<\/string.*//;p;}' Locale.xml | tail -1 But is there any option in sed by which I can get second value only? 回答1: You can use this sed , sed -n '/LANGUAGE/{N; s/

How can I run a csh script from a tcl script?

会有一股神秘感。 提交于 2019-12-07 08:29:05
问题 I am trying to run a csh script from a tcl script. The tcl script below calls a csh script #!/usr/bin/tclsh set scripts_path /scratch/TCL_scripts/scripts_adders set synthesis /scratch/TCL_scripts/synthesis.csh set files [glob -directory $scripts_path *] split $files set files [lsort $files] set i 1 foreach script $files { puts "hello" # puts [pwd] exec /bin/csh -c $synthesis puts $i } And the (begining of the) csh file is below: #!/bin/csh -f echo abcdefgh When I only execute the csh file

How to run a tcsh shell command and selectively ignore the status?

隐身守侯 提交于 2019-12-07 05:58:29
问题 I've got a tcsh shell script that I would like to stop with an error on nonzero status most of the time, but in some cases I want to ignore it. For example: #!/bin/tcsh -vxef cp file/that/might/not/exist . #Want to ignore this status cp file/that/might/not/exist . ; echo "this doesn't work" cp file/that/must/exist . #Want to stop if this status is nonzero 回答1: I don't know about tcsh, but with bash, you can use set -e to do this. When the -e flag is set, bash will exit immediately if any

alias in cshell with grave accents, apostrophes and more

落花浮王杯 提交于 2019-12-06 08:11:31
问题 I came across a weird behavior in the c-shell: when writing the following line, i get exactly the behavior I expect: ls -l | grep $USER | somescript `awk -F' ' '{print $1}'` meaning - it will search all items owned by me and activate 'somescript' with their first field as argument. however, when I try aliasing the same line, it jams my shell (or hands out error massages if i separate the braces from the apostrophe: alias doit 'ls -l | grep $USER | somescript `awk -F' ' '{print $1}'`' will

Why doesn't rm work as I expect here?

徘徊边缘 提交于 2019-12-06 07:26:30
问题 I just want to do a simple thing. I got the following files in a directory: AppInterface.h baa PEMsg.h PluginInterface.h Then I issue the command: ls | grep -v ".h" | rm -rf Much to my dismay, baa does not get deleted. But, this: ls | grep -v ".h" gives baa as I expect. So I guess the problem is with how rm takes input but I don't know why. Tried this both in csh and bash. 回答1: rm doesn't take input from stdin so you can't pipe the list of files to it. You need rm `ls | grep -v ".h"` or ls |

ampersand at beginning of a line in csh

房东的猫 提交于 2019-12-05 19:28:05
What does an ampersand at the beginning of a line do in csh? It seems to be ignored (with no error message), but why? Found something interesting: The semicolon (;) character separates successive commands on a single command line. For example, % <command1> ; <command2> executes <command1>, and when it finishes, <command2> gets executed. The ampersand character (&) is similar to the semicolon (;) but does not wait for <command1> to finish. Maybe it's treating it like an empty command? The best way to answer will be example. Taking idea of JoelFAn ahaed: EXAMPLE 1 user$ date ; sleep 5s ; date