csh

Whats wrong with this C shell script?

前提是你 提交于 2019-12-11 03:37:41
问题 I am trying to write a C shell equivalent script for the bash script mentioned here. This is what I have : #! /bin/tcsh set now=`date +%Y%m%d%H%M.%S` if (( ! -f "./cache" ) || (-n "`find ./monme -newer ./cache`" )) then touch cache -t "$now" echo "new files added" | mail -s "new build" myemail@myserver.com endif and this is the error I get $ ./scr if: Badly formed number. $ This page mentions that "Numbers in the C-shell must be integers", so I tried set now=`date +%Y%m%d%H%M` but I get the

Csh issue with Illegal variable name

那年仲夏 提交于 2019-12-11 02:13:08
问题 Ok that's my whole code I have a new Error: Illegal variable name. When I execute the file with: csh filename.sh Result is: Illegal variable name. I think that the problem containing in the part of: while ( $? == 1 ) #!/bin/sh set quitter = "N" # Boucle sur la condition d'arret du script: while ( $quitter == "N" ) # Saisie du nom de l'utilisateur : echo "Quel utilisateur ?" set a = $< # Mettre le résultat de la commande ps -u # dans un fichier quelque soit le résultat (juste ou faux) : ps -u

Cannot set tcsh exit status using a variable

你说的曾经没有我的故事 提交于 2019-12-11 02:12:46
问题 I usually use bash, but in this case I must use tcsh. To my surprise, I cannot use a variable containing the exit status as the argument to exit : [bash] tcsh [tcsh] set status=2 [tcsh] echo $status 2 [tcsh] exit $status exit [bash] echo $? 0 A literal argument to exit does work as expected: [bash] tcsh [tcsh] exit 2 exit [bash] echo $? 2 What on earth is going on here? 回答1: $status is a built-in C shell variable containing the exit status of the previous command. Try echoing $status twice

How to write If-else statement in one line in csh?

强颜欢笑 提交于 2019-12-10 23:57:41
问题 I use Cshell and i'm writing an if else statement in oneLine. If statement executed successfully and else block is going for infinite loop and cannot exit back to promt. Any suggestion how it can be solved? /home/sun_cdmasee>if ( 25 == 25 ) then ; echo "yes" ; else echo "no" ; endif yes else? else? else? 回答1: The man page says it's not possible: (The words else and endif must appear at the beginning of input lines; the if must appear alone on its input line or after an else .) Don't try to

How to dereference a variable in CSH

一曲冷凌霜 提交于 2019-12-10 23:03:17
问题 I have a variable $var that has values as another variable $env . $env has some value . how can I use $var to print the value of $env. > set xyz = 'abc' set env = 'xyz' set v = '$' set var = "$v""$env" > > echo $var o/p: $xyz now I want to print the value the of $ xyz using $var 回答1: Use eval , like this: set xyz='abc' set var='xyz' eval echo \$$var This is more commonly known as an indirect reference . Here is an example script: set var = 'xyz' set xyz = 'abc' if ( $?var ) then echo '$var is

variable of Variable

拥有回忆 提交于 2019-12-10 20:57:28
问题 I have to print a variable value which is art variable. eg. variables are A = X Z_X = Test Set in shell using setenv A X setenv Z_X Test I want to print $Z_X value using $A I am trying but without any success. echo ${Z_${A}} echo ${Z_[$A]} could anyone tell me where I am wrong. regards 回答1: A = X Z_X = Test This seems wrong; in csh , you need to use the set keyword to assign variables; in addition, the convention is also to use lower case for "normal" variables, and UPPER CASE for environment

Aliasing find directory in Unix

拜拜、爱过 提交于 2019-12-10 20:23:38
问题 I tried something like: alias fdi 'find . -type d -iname "*\!^*"' but this only looks for exact names passed as argument. fdi abc will only output: ./d/abc not this: ./d/greabcyup I am not just looking for exact name. It should also show ./d/greabcyup Update: I did echo $0 tcsh 回答1: Is this c-shell or tcsh? I dbl-checked with orielly lunix in a nutshell , !^ is meant to be the first word in the current command line, so I don't think it is doing what you want. You can dbl check that theory for

Invoking shell from java, it complaints “stty: standard input: Invalid argument”

只愿长相守 提交于 2019-12-10 04:33:49
问题 I invoke a shell command by Process class from java and it prints "stty: standard input: Invalid argument" no matter whether the command is right or wrong (normal output of shell command is shown too). If I run the shell command in shell, no such error message is shown. The command is something like this: {"/bin/csh", "-c", "echo hello"} 回答1: Try using the -f option of csh to disable the reading of the .chsrc and .login files: {"/bin/csh", "-cf", "echo hello"} 回答2: You are invoking the stty

Redirecting stderr in csh

◇◆丶佛笑我妖孽 提交于 2019-12-10 02:36:21
问题 I'm executing a program that dumps crash report into STDERR from where I have to filter some necessary information. The problem is that I'm unable to redirect STDERR to STDOUT and PIPE it with grep command 2>&1 >/dev/null | grep "^[^-]" >& /tmp/fl Getting error: Ambiguous output redirect. Same command works under bash terminal. What should I change to make it work ? 回答1: csh is significantly more limited than bash when it comes to file redirection. In csh , you can redirect stdout with the

How can I check if a variable is empty or not in tcsh Shell?

好久不见. 提交于 2019-12-09 14:20:08
问题 IF I have to check that if a variable is empty or not for that in bash shell i can check with the following script: if [ -z "$1" ] then echo "variable is empty" else echo "variable contains $1" fi But I need to convert it into tcsh shell. 回答1: The standard warnings regarding use of tcsh / csh apply, but here's the translation: if ( "$1" == "" ) then # parentheses not strictly needed in this simple case echo "variable is empty" else echo "variable contains $1" endif Note, though, that if you