Questions tagged [csh]

csh, or the C shell, is a command interpreter with a syntax reminiscent of the C programming language.

Quoted from the Solaris csh man page:

csh, the C shell, is a command interpreter with a syntax reminiscent of the C language. It provides a number of convenient features for interactive use that are not available with the Bourne shell, including filename completion, command aliasing, history substitution, job control, and a number of built-in commands. As with the Bourne shell, the C shell provides variable, command and filename substitution.

csh first appeared in 2BSD, and was originally created by Bill Joy. While Bourne shells are more popular, csh-style shells are still fairly popular especially in the BSD community & academia.

is an an enhanced version of csh, almost all versions of csh encountered nowadays are actually tcsh.

Programming in csh is a controversial topic. For one viewpoint, see this article.

1173 questions
7
votes
5 answers

csh/sh for loop - how to?

i'm trying to write a for loop that executes 2 scripts on FreeBSD. I don't care if it's written in sh or csh. I want something like: for($i=11; $i<=24; $i++) { exec(tar xzf 'myfile-1.0.' . $i); // detect an error was returned by the script …
Paul J
  • 777
  • 2
  • 8
  • 18
7
votes
1 answer

how can I recall previous commands' arguments? (in csh, and in bash?)

I usually use csh (actually my /bin/csh is linked to tcsh, an improved version of csh) and frequently use !$ to refer to the last argument of the last command. But sometimes I would like to use the last two arguments of the previous command. How can…
Chan Kim
  • 5,177
  • 12
  • 57
  • 112
7
votes
4 answers

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

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…
mmccoo
  • 8,386
  • 5
  • 41
  • 60
7
votes
1 answer

Move files that are 30 minutes old

I work on a server system that does not allow me to store files more than 50 gigabytes. My application takes 20 minutes to generate a file. Is there any way whereby I can move all the files that are more than 30 minutes old from source to…
saurabh
  • 391
  • 1
  • 2
  • 11
7
votes
2 answers

What does $?VAR mean in csh?

I've encountered this code written in csh: if ( ! $?LM_LICENSE_FILE ) then setenv LM_LICENSE_FILE $_LmLicense else switch("$LM_LICENSE_FILE") case *${_LmLicense}*: breaksw default: setenv LM_LICENSE_FILE…
wangshuaijie
  • 1,821
  • 3
  • 21
  • 37
6
votes
6 answers

What is the best (portable and maintanable) Shell Scripting language today?

I know this question has kind-a started "religious" wars in past and there might not be one correct answer. But after working with ksh and csh for last 3-4 years and going through the pain of porting from one to another or applying a common piece of…
Devang Kamdar
  • 5,617
  • 8
  • 24
  • 16
6
votes
1 answer

if-else on arguments in npm run script

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…
Frank N
  • 9,625
  • 4
  • 80
  • 110
6
votes
5 answers

How can I read one line at a time with C shell in unix

I try to make a small script, using c shell, that will take a file made of several lines, each containing a name and a number and sum all numbers that a have certain name. How can I put into a variable the next line each time? the summig part I do…
SIMEL
  • 8,745
  • 28
  • 84
  • 130
6
votes
3 answers

Declaring User Defined Variable in Shell Scripting (csh shell)

I am trying to learn shell scripting and trying to create a user defined variable within the script, first: howdy="Hello $USER !" echo $howdy However, when I execute the script (./first) I get this: howdy=Hello aaron!: Command not found. howdy:…
Elpezmuerto
  • 5,391
  • 20
  • 65
  • 79
6
votes
4 answers

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

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…
solotim
  • 1,826
  • 4
  • 24
  • 41
6
votes
2 answers

how do I guard against "foreach: No match"?

I've got a shell script that looks like this: foreach dir (i686.* amd64.*) # commands end The problem with this script is that if there are no directories matching those names then I get the following error: "foreach: No match." What's an…
dromodel
  • 9,581
  • 12
  • 47
  • 65
6
votes
2 answers

Substitution of ! with sed leads to event not found

I need to change every occurrence of ! to : as field separators in a group file. sed 's/!/:/g' filename > newfilename But I get the error /: Event not found?
user2358660
  • 65
  • 1
  • 3
6
votes
3 answers

How can I determine my csh version?

I have some code which works for me, but when I gave it to some colleagues, it broke. They're using tcsh whereas, as far as I can figure, I'm using csh. I've tried: csh -v csh --version csh -V csh --help csh -h with no success (they all just take…
mgilson
  • 300,191
  • 65
  • 633
  • 696
6
votes
6 answers

How to make exit behave when "sourced" in csh

csh is an utterly horrible shell. (Making that statement up front to avoid the inevitable comments of "don't use csh", or perhaps I should just state that for the sake of any readers: please, if you value your sanity, do not use csh.) I have a…
William Pursell
  • 204,365
  • 48
  • 270
  • 300
6
votes
2 answers

Csh adding strings to an array, whitespace troubles

I’m having trouble doing something basic with csh. I have a string: set newCmd = "$expansionCmd –option1 –option2 …" And I’m creating an array of these strings, which I later want to execute: set expansionCmdList = ($expansionCmdList[*] "$newCmd") …
JDS
  • 16,388
  • 47
  • 161
  • 224