Skip to main content
33 votes
Accepted

How does a shell know home(s)?

In the case of csh and tcsh, it records the value of the $HOME variable at the time the shell was started (in its $home variable as noted by @JdeBP). If you unset it before starting csh, you'll see ...
Stéphane Chazelas's user avatar
25 votes

How to determine the path to a sourced tcsh or bash shell script from within the script

This worked for me in bash, dash, ksh, and zsh: if test -n "$BASH" ; then script=$BASH_SOURCE elif test -n "$TMOUT"; then script=${.sh.file} elif test -n "$ZSH_NAME" ; then script=${(%):-%x} elif ...
Paul Brannan's user avatar
25 votes
Accepted

Avoiding non-zero exit code when running `ls` using multiple patterns

Most of your questions are already answered at Why is nullglob not default?. One thing to bear in mind is that: ls -d /some/{path1,path2}/* In csh/tcsh/zsh/bash/ksh (but not fish, see below) is the ...
Stéphane Chazelas's user avatar
18 votes

Error "syntax error near unexpected token `('?"

Follow the actual installation instructions properly! You buried this in a comment:The environment variables are written to settings[32|64].(c)sh at "/opt/Xilinx/14.7/ISE_DS". To launch the Xilinx ...
JdeBP's user avatar
  • 69.5k
15 votes

while command not working when bash script is sourced in tcsh?

This error? $ tcsh tcsh> source while.sh i=1: Command not found. while: Expression Syntax. tcsh> exit Csh/tcsh is a different shell than POSIX sh or Bash. Trying to run a script in sh syntax ...
ilkkachu's user avatar
  • 141k
12 votes

Error "syntax error near unexpected token `('?"

bash doesn't have a foreach; this script is probably meant to run in csh or tsch. If you are invoking the script with ./myscript.csh, make sure its first line is #!/bin/csh (or whatever the full path ...
DopeGhoti's user avatar
  • 76.9k
12 votes
Accepted

When defining an environment variable, I get "Command not found"

That's the right command to set a shell variable. Or would be, in a POSIX shell. It doesn't actually export the variable to the environment of commands you run, though. To do that, you'd need export ...
ilkkachu's user avatar
  • 141k
9 votes
Accepted

tcsh preserve newlines in command substitution `...`

There are plenty of good reasons why it's recommended not to use csh or tcsh for scripting. That's one of those. To get the output of some command verbatim into a shell variable in tcsh, you need ...
Stéphane Chazelas's user avatar
9 votes
Accepted

How to remove a single command from TCSH history?

I don't use tcsh, but perusing the man page suggests: save current history with history -S edit the history file to remove the offending command with vi ~/.history (or vi $histfile, if you've ...
glenn jackman's user avatar
7 votes

Preserve tcsh history in multiple terminal windows

In addition to Idan answer, I want to add that alias precmd 'history -S; history -M' potentially can mess up the history file, since it also records SIGINT and EOF signal (Ctrl+C and Ctrl+D). A ...
berong91's user avatar
7 votes

How does a shell know home(s)?

So how does the shell know where is my/other_user home? It doesn't. You're just not performing the experiment properly. As you can see from the C shell manual, the cd command changes to the value ...
JdeBP's user avatar
  • 69.5k
6 votes
Accepted

less command stops working after setting terminal title in .tcshrc

Your less is probably configured to pipe its output through lesspipe or a similar script. This happens if environment variable LESSOPEN and/or LESSCLOSE is set, or an equivalent setting is used in ...
telcoM's user avatar
  • 101k
6 votes
Accepted

find with -prune leaves pruned directory names

-prune excludes the directory's contents, but not the directory itself. This happens if -prune is the only action in a find command. If there were any other action (e.g. -exec or -print), it would ...
cas's user avatar
  • 79.2k
6 votes

How to produce a PS1 prompt in bash or ksh93 similar to tcsh

For bash, you could achieve similar results by setting the PROMPT_DIRTRIM variable: $ PS1='[\u@\h] \w\$ ' [schaller@r2d2] ~$ pwd /home/schaller [schaller@r2d2] ~$ PROMPT_DIRTRIM=3 [schaller@r2d2] ~$ ...
Jeff Schaller's user avatar
  • 67.7k
6 votes
Accepted

How to understand which shell a particular code belongs to without knowledge about the shell?

for f in $file.docked.[0-9][0-9][0-9] do mv $f $f.pdb done Is syntactically valid code in csh, tcsh and all shells of the Bourne family (ash, bash, zsh, ksh, zsh, mksh, yash...) but it's in zsh that ...
Stéphane Chazelas's user avatar
5 votes
Accepted

creating alias for cmd with backticks

You can change the quoting a bit to not allow the backticks to be evaluated until when the alias is used. alias ncstop 'nc stop `nc list | awk '\''/Running/{print $1}'\''`' This works because when ...
Stephen Rauch's user avatar
5 votes
Accepted

tcsh - echo escape code for escape

printf expands those in the format (first) argument by itself, no need for those ksh93-style $'...' quotes. So: printf '\33[2J\33[H' Note that printf is not a builtin in tcsh, so you'd be calling ...
Stéphane Chazelas's user avatar
5 votes
Accepted

problem with loading tcshrc

One possible reason: you actually have an invalid character in there, accidentally added when creating the file. It would have to be something that's normally not (very) visible, for example, a non-...
ilkkachu's user avatar
  • 141k
5 votes

tcsh bindkey to turn on readline variable `visible-stats`

readline is a library that is used by bash and some other software, but not by tcsh. For historical reasons, tcsh has its own implementation of readline-like functionality, whose feature set does not ...
telcoM's user avatar
  • 101k
5 votes

Is there a shopt glob setting or setting combo that behaves like tcsh?

The only shopt options related to filename expansion are dotglob, failglob, nocaseglob and nullglob, and none of them (alone or combined) seem to do exactly what you want. It's a shame because that ...
nxnev's user avatar
  • 3,694
5 votes
Accepted

tcsh grep trouble

This isn't a problem with grep - it's a problem with the unquoted variable expansion in echo $query and the fact that the matched line returned by grep contains the globbing character *. In tcsh, the ...
steeldriver's user avatar
  • 81.9k
5 votes
Accepted

tcsh scripting - keep newlines of grep results

"the output I get is just one line" - unfortunately you've just hit one of the reasons why scripting in [t]csh is problematic. Keeping newlines is either not possible or non-trivial. Use ...
Chris Davies's user avatar
5 votes
Accepted

DISPLAY=:0: Command not found

tcsh has different syntax from Bash. To set your variable in that shell and make it available for the programs you'll call, you have to use the following command: setenv DISPLAY :0 ssh .... Or if you ...
giusti's user avatar
  • 1,737
5 votes

tcsh: Handle spaces in arguments when passing on to another command

Use an array. csh was the first shell with support for arrays from the late 70s. There are many things csh/tcsh got horribly wrong, including quoting, to the point that most people (me included) would ...
Stéphane Chazelas's user avatar
4 votes

How to determine the path to a sourced tcsh or bash shell script from within the script

To make your script both bash- and zsh-compatible instead of using if statements you can simply write ${BASH_SOURCE[0]:-${(%):-%x}}. The resulting value will be taken from BASH_SOURCE[0] when it's ...
dols3m's user avatar
  • 141
4 votes

How to determine the path to a sourced tcsh or bash shell script from within the script

I was a bit confused by the community wiki answer (from Shawn J. Goff), so I wrote a script to sort things out. About $_, I found this: Usage of _ as an environment variable passed to a command. It's ...
Mathieu CAROFF's user avatar
4 votes

ls to show only directory/filename and size

In the spirit of "not parsing ls output", why not use find?: find . -mindepth 1 -maxdepth 1 -printf '%p\t%s\n' (here assuming GNU find for its -printf extension). Replace . with "$PWD&...
Missing Semicolon's user avatar
4 votes
Accepted

What is special about printf over echo

The easiest way to see this is to use something like od -c which prints all characters: $ echo 123456 | od -c 0000000 1 2 3 4 5 6 \n 0000007 $ printf 123456 | od -c 0000000 1 2 3 ...
terdon's user avatar
  • 245k

Only top scored, non community-wiki answers of a minimum length are eligible