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
14
votes
2 answers

Explain the deviousness of the Perl "preamble"

The Perl manual describes a totally devious construct that will work under any of csh, sh, or Perl, such as the following: eval '(exit $?0)' && eval 'exec perl -wS $0 ${1+"$@"}' & eval 'exec /usr/bin/perl -wS $0 $argv:q' if…
JoelFan
  • 37,465
  • 35
  • 132
  • 205
13
votes
3 answers

In csh, why does 4 - 3 + 1 == 0?

#!/bin/csh @ cows = 4 - 3 + 1 echo $cows This simple csh script when run produces "0" for output when I'd expect "2". ~root: csh simple.1 0 I did a bunch of looking and the only thing I could think of was that the "-" was being read as a unary…
Instantsoup
  • 14,825
  • 5
  • 34
  • 41
12
votes
3 answers

How do I split a String in CSH?

For example, I want to split "one,two,three" with comma as delimiter and use a loop to process the resulted three substring separately.
twimo
  • 4,061
  • 5
  • 29
  • 32
12
votes
8 answers

How to add date string to each line of a continuously written log file

Having a long running program that continuously writes to a logfile - how is it possible, disregarding any buffering issues, to add a date string to each line written to that file using a linux script? I would imagine something like this: tail -f…
bmk
  • 13,849
  • 5
  • 37
  • 46
12
votes
5 answers

how to write foreach in one line in csh?

Sometimes I use same foreach operation with different target files in csh. If I can give foreach command in a single line, I could easily substitue the target file names to repeat the process.(I usually use `find . -name ...` for target files) For…
Chan Kim
  • 5,177
  • 12
  • 57
  • 112
12
votes
5 answers

$0 doesn't work when I source a bash script

I have a simple script test.sh #!/bin/bash echo $0 When I run the following from csh terminal: bash -c 'test.sh' Then the output is test.sh But when I run: bash -c 'source test.sh' The output is bash Does anybody know how to print the script name…
Morad
  • 2,761
  • 21
  • 29
12
votes
1 answer

Pass arguments from csh to program, exactly as they are

I have a csh script, which is executed using "source", and passes all its arguments to a program: % alias foo source foo.csh % cat foo.csh ./bar $* # Some uninteresting stuff If I run source foo.csh a b c, all is OK. But not always: foo "a b" "c…
ugoren
  • 16,023
  • 3
  • 35
  • 65
12
votes
4 answers

Why do unix background processes sometimes die when I exit my shell?

I wanted to know why i am seeing a different behaviour in the background process in Bash shell Case 1: Logged in to Unix server using Putty(SSH) By default it uses csh shell I changed to bash shell typed sleep 2000 & press enter It gave me the…
user177558
11
votes
3 answers

How to add loop counter to foreach in csh

In CSH foreach loop or for loop, how can I add a loop iterator or counter which increases from 10 to 1000 with steps of 20? Something like foreach i (1..20..5) or for (i=1;i<20;i++).
SkypeMeSM
  • 3,197
  • 8
  • 43
  • 61
11
votes
3 answers

Find command to return absolute path

I'm using find command a lot on unix (csh). Is it possible that the result will be full/absolute path and will start from the directory where I'm starting the search for example when running command from /project/Test/v0.15/test/frontend, the …
Jonathan
  • 285
  • 3
  • 9
11
votes
3 answers

how to pass numeric array from bash to csh

Firstly, in my defense: I'm only using csh because my group has a lot of legacy csh. We do scientific programming; a lotta folks apparently learned to use csh back in the SunOS/Solaris days, and didn't give up despite the linux/bash transition, and…
TomRoche
  • 1,464
  • 1
  • 16
  • 25
11
votes
1 answer

How to use the qsub -v command in PBS torque?

I would like to pass variables to a csh script by using "qsub -v" command. I understand we can list the parameters-value pairs as below, qsub -v par1=value1 par2=value2 myScript.csh Does anyone know if the values of these parameters can be a…
Cassie
  • 1,179
  • 6
  • 18
  • 30
10
votes
1 answer

sorting in shell script

I have an array arr=( x11 y12 x21 y22 x31 y32) I need to sort this array to x11 x21 x31 y12 y22 y32 So, I need to sort both alphabetical and numerical wise How do I perform this in shell script ? If I use [ $i -le $j ], it says "integer expression…
user691197
  • 927
  • 6
  • 20
  • 38
10
votes
2 answers

Simple way to append to an environment variable that may not exist yet in csh

I am trying to append a path to the end of my PERL5LIB environment variable, but I am not sure that this variable will always exist. If it doesn't exist I would like to simply initialize it to the value that I am trying to append. Here is an example…
tjwrona1992
  • 8,614
  • 8
  • 35
  • 98
10
votes
2 answers

cshell tab completion , case insensitive

For C Shell is there a way to make tab completion for commands, files etc. case insensitive? I saw the complete=enhance variable, but that is only for tcsh, not csh.
Ratheesh Pai
  • 1,600
  • 1
  • 15
  • 24
1 2
3
78 79