Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
2
votes
3
answers
4636
views
CSH and all output (with errors) to file
I need save all output from compilation to file. I have many errors `undefined reference` and I want see all of these errors. I try `makeall >& out`, but in file `out` aren't any of error `undefined reference`. I must use `csh` to run `makeall`.
I need save all output from compilation to file. I have many errors
undefined reference
and I want see all of these errors.
I try makeall >& out
, but in file out
aren't any of error undefined reference
.
I must use csh
to run makeall
.
marcin
(65 rep)
Mar 27, 2015, 10:32 AM
• Last activity: Jun 30, 2025, 08:03 AM
1
votes
1
answers
54
views
How to define a recursive alias in csh (intentionally!)
It is known that attempting to invoke a custom alias inside itself (be it directly; or indirectly via intermediate aliases that call each other) would cause an "**`Alias loop.`**" error, and rightfully so. However, I would like to write a recursive `csh` alias, as I intend to include a base case to...
It is known that attempting to invoke a custom alias inside itself (be it directly; or indirectly via intermediate aliases that call each other) would cause an "**
Alias loop.
**" error, and rightfully so.
However, I would like to write a recursive csh
alias, as I intend to include a base case to the recursion, so in my use case it is not an infinite loop. Here's a simplified example:
alias countdown 'if ( \!* > 0 ) then; echo \!*; countdown expr \!* - 1
; endif;'
The expected output from this alias, for example with input 3, should be:
$ countdown 3
3
2
1
0
Attempting to define such an alias leads to the aforementioned "**Alias loop.
**" error on csh
. How can I achieve this functionality correctly? I tried using a while loop in the alias instead of recursion, but [it doesn't seem to be supported in csh
](https://stackoverflow.com/a/61298726/10679420) , and [other workarounds for this alias loop issue](https://unix.stackexchange.com/q/28704/459071) are not applicable since I do not have a built-in counterpart to invoke.
Vadrif Draco
(111 rep)
May 11, 2025, 01:05 PM
• Last activity: Jun 2, 2025, 06:50 AM
0
votes
1
answers
2678
views
How to execute an alias, encapsulated in another source file?
For instance `~/.cshrc`: `alias job_start 'cd $PROJ_DIR && source .env/bin/activate.csh && rehash && job_run'` `$PROJ_DIR/.env/bin/activate.csh`: alias job_run '(cd $PROJ_DIR/builds; sh run.sh)' after calling job_start: % job_start [4/36] job_run: Command not found. But aliases updates after calling...
For instance
~/.cshrc
:
alias job_start 'cd $PROJ_DIR && source .env/bin/activate.csh && rehash && job_run'
$PROJ_DIR/.env/bin/activate.csh
:
alias job_run '(cd $PROJ_DIR/builds; sh run.sh)'
after calling job_start:
% job_start [4/36]
job_run: Command not found.
But aliases updates after calling job_start
-> job_run
appears.
Manually calling job_run
will proceed as expected.
kAldown
(277 rep)
Jan 25, 2017, 10:45 AM
• Last activity: Mar 27, 2025, 10:03 PM
2
votes
1
answers
1422
views
Sync terminal history in c shell
For work, I remote into a linux server that uses c shell rather than bash using Remote Desktop. While in session (lets call it session 1) I'll open up many tabs in a given terminal and type commands throughout all of them. I'll also sometimes open up additional sessions (lets call them session 2 and...
For work, I remote into a linux server that uses c shell rather than bash using Remote Desktop. While in session (lets call it session 1) I'll open up many tabs in a given terminal and type commands throughout all of them. I'll also sometimes open up additional sessions (lets call them session 2 and session 3) with many tabs in their respective terminals and type many commands throughout all of them.
I have noticed that the history command when invoked in any tab of any terminal across any session does not include all of the commands I have used across all of the tabs and sessions. only part of the commands are saved.
I would like a history that:
- Remembers *all* commands typed, regardless of what tab, terminal or session I am in
- Instantly accessible from any of tabs/terminals/sessions
While there is a great post from nearly 12 years ago that describes how to do exactly this, that is for a bash environment, not a c shell environment. As such, there is no
.bashrc
but rather a .cshrc
. I'm looking for a solution that works in the c shell environment.
UPDATE:
I tried adding this to the top of the .cshrc
file:
set history=10000
set savehist=(10000 merge)
alias precmd 'history -L, history -S'
Where set history=10000
sets the size of the history list,
set savehist=(10000 merge)
sets the number of lines in the history list to save to the .history
upon exit of a session, and the merge merges the history of a session with the overall history upon exit,
alias precmd 'history -L; history -S'
sets some commands to run before every command at the terminal is ran. The -L
option appends a history file to the current history list. The -S
option writes the history list to a file.
This didn't do what I wanted. Now every time I type history at the terminal, the size of the command history list jumps up in size _dramatically_. The command history list _isn't_ updated across terminal tabs in a session.
I tried this too, with no improvement:
set history = 10000
set histdup = erase
set savehist = (${history} merge lock)
alias precmd 'history -S'
alias postcmd 'history -M'
I'm not entirely sure what all of the lines mean, but I know that precmd
supposedly means before a command is ran, do this and postcmd
supposedly means after a command is ran do this. The -M
option merges the contents of the history file with the current history list and sorts the resulting list by the timestamp contained with each command.
I feel like I am close, like I'm missing some key line to add in the .cshrc
file, or maybe I need to change the order around.
Dan
(21 rep)
Feb 1, 2022, 06:42 PM
• Last activity: Jan 1, 2025, 07:14 PM
18
votes
2
answers
2002
views
What exactly is a scratch file (starting with #)? Does it still work today?
I've been reading up on some Unix history and got interested into the `csh` because it's installed by default on OpenBSD. In the `csh` manpage it had a reference to "W Joy - An Introduction to the C shell", which I could get a hold of. Therein, in Chapter 1.3 it explains simple file redirection and...
I've been reading up on some Unix history and got interested into the
csh
because it's installed by default on OpenBSD.
In the csh
manpage it had a reference to "W Joy - An Introduction to the C shell", which I could get a hold of. Therein, in Chapter 1.3 it explains simple file redirection and makes an example, quite perplexing to me:
> The system normally keeps files which you create with ‘>’ and all other files. Thus the default is for
files to be permanent. If you wish to create a file which will be removed automatically, you can begin its
name with a ‘#’ character, this ‘scratch’ character denotes the fact that the file will be a scratch file.* The
system will remove such files after a couple of days, or sooner if file space becomes very tight. Thus, in
running the date command above, we don’t really want to save the output forever, so we would more likely
do
>
> date > #now
Now I never heard of a scratch file. Is this a long forgotten thing? Does it still work today? Is it just disabled? When will it get deleted (couple days?)? by what (cron?)?
I've run the command on an OpenBSD and on a Linux System (date > '#now'
because its a comment in /bin/sh
), but I can't wait (or might just answer myself in a "couple days").
Does anybody know more about this, preferably some more history. I couldn't find anything from few a quick searches.
Thanks in advance!
MarcDefiant
(291 rep)
Sep 23, 2024, 10:26 PM
• Last activity: Sep 25, 2024, 07:14 AM
7
votes
3
answers
31593
views
How to debug csh scripts?
My lab uses csh scripts to run jobs. It is usually difficult for me to debug a shell script, so I'm wondering if there is a csh debugger I can use. I know there are some flags like `-x` or `-v` that can help, but because the script is kind of long, it would be better if I can set breakpoints on it....
My lab uses csh scripts to run jobs. It is usually difficult for me to debug a shell script, so I'm wondering if there is a csh debugger I can use.
I know there are some flags like
-x
or -v
that can help, but because the script is kind of long, it would be better if I can set breakpoints on it. As I searched online, I found there is a debugger specifically for bash scripts that supports breakpoints, but I couldn't find one for csh scripts. Will the bash debugger work? Is there a csh-specific debugger I can use?
Cassie
(221 rep)
Oct 8, 2012, 09:17 PM
• Last activity: Jul 22, 2024, 09:24 PM
2
votes
1
answers
2037
views
Setting environment variable using shell script
I am using csh scripts for some automation purpose. I have a number of scripts, and the beginning of all of which I need to set a fixed set of environment variables. |----SCRIPT 1---| |----SCRIPT 2---| |# set env vars | |# set env vars | | | | | |# do something | |# do something | | | |# else | So I...
I am using csh scripts for some automation purpose. I have a number of scripts, and the beginning of all of which I need to set a fixed set of environment variables.
|----SCRIPT 1---| |----SCRIPT 2---|
|# set env vars | |# set env vars |
| | | |
|# do something | |# do something |
| | |# else |
So I thought that I'll put all the environment variables in another script and source it from each file. But as it turns out, environment variables set inside the sourced script are not reflected outside. Is there any clean way to achieve what I want? Or do I have to explicitly set environment variables in each script ?
**UPDATE :**
While sourcing the file, I was piping the output to a file using the 'tee' command. I noticed that after removing the pipe, the script file worked.
johngreen
(131 rep)
Jan 19, 2016, 05:56 AM
• Last activity: Jun 21, 2024, 01:05 PM
0
votes
1
answers
133
views
cleartool command not found from .cshrc but found when manually called
I'm having an issue with `cleartool` commands called from my `.tcshrc`. I try to call `cleartool setview`, but get a `cleartool: Command not found` error. however, when I call the command from the terminal, I don't get this issue. My default shell is set to `tcsh`, and I have `csh`, `sh`, `tcsh` all...
I'm having an issue with
cleartool
commands called from my .tcshrc
. I try to call cleartool setview
, but get a cleartool: Command not found
error. however, when I call the command from the terminal, I don't get this issue. My default shell is set to tcsh
, and I have csh
, sh
, tcsh
all present in my /bin
dir. What could be causing this issue?
My $PATH
when output from the init script is as follows:
/usr/lib64/qt-3.3/bin:/usr/share/centrifydc/bin:/usr/local/bin:/bin:/usr/bin:/opt/dell/srvadmin/bin
The path when echo
'd from the terminal is significantly longer; I can't show the whole thing because it's on a corporate system but it does contain /opt/rational/clearcase/bin
, so I believe this is the problem but I don't know how to get the script to recognise the longer path.
The script works if I add a line to my script to add /opt/rational/clearcase/bin
to $PATH
, but I'd like to be able to permanently add this to my shell path.
Clinton J
(101 rep)
Jun 5, 2024, 07:16 PM
• Last activity: Jun 11, 2024, 06:12 PM
0
votes
2
answers
81
views
Find files created after a particular time in csh on SunOS
On my SunOS system, I'm trying to find all files created after 7 PM using `csh`, `ls`, and `awk`. ``` ls -l "${Source_files_Dir}"/*.zip| awk -v today="$(date "+%b %d")" '{ date=$6" "$7; time=$8; if (date == today && substr(time,1,2) >= 19) print $9 }'|xargs -n 1 basename ``` This command works in `k...
On my SunOS system, I'm trying to find all files created after 7 PM using
csh
, ls
, and awk
.
ls -l "${Source_files_Dir}"/*.zip| awk -v today="$(date "+%b %d")" '{
date=$6" "$7; time=$8; if (date == today && substr(time,1,2) >= 19)
print $9 }'|xargs -n 1 basename
This command works in ksh
but not in csh
. How can I achieve this in csh
?
Note: -newermt
option is not supported by find
on SunOS, so I tried to use the above ls
command.
Aravind
(1679 rep)
Apr 22, 2024, 01:13 PM
• Last activity: Apr 25, 2024, 12:15 PM
2
votes
1
answers
1914
views
Is there a way to disable history for one command in TCSH?
I am executing a command in TCSH, which requires me to pass a password on the command line. Obviously, I would like it not to be saved in the history file. I know that other shells like Bash supports various ways to achieve it, like `export HISTCONTROL=ignorespace`. Is there anything similar for TCS...
I am executing a command in TCSH, which requires me to pass a password on the command line. Obviously, I would like it not to be saved in the history file.
I know that other shells like Bash supports various ways to achieve it, like
export HISTCONTROL=ignorespace
.
Is there anything similar for TCSH (preferably on FreeBSD)?
Mateusz Piotrowski
(4983 rep)
Jun 29, 2020, 11:05 AM
• Last activity: Jan 19, 2024, 12:31 PM
0
votes
2
answers
146
views
Load files in sequential order
I need to load multiple files in my shell script with the same filename but appended in the front of each file name is YYMMDDPERSONNEL Examples: 231102PERSONNEL and 230103PERSONNEL There are many other files in the same directory so filenames are important in the sort. I need to sort files to be loa...
I need to load multiple files in my shell script with the same filename but appended in the front of each file name is YYMMDDPERSONNEL
Examples: 231102PERSONNEL and 230103PERSONNEL
There are many other files in the same directory so filenames are important in the sort.
I need to sort files to be loaded from the oldest to the newest.
Currently what I have is only designed to handle one file at a time.
teejay
(9 rep)
Nov 7, 2023, 05:05 PM
• Last activity: Nov 12, 2023, 08:19 AM
0
votes
0
answers
45
views
Substitute square bus in csh script
I have input list: `adr[0]` `adr[1]` `xadr[0]` I want my output is: `adr[*]` `adr[*]` `xadr[*]` #! /bin/csh -fv set list = "adr[0] adr[1] xadr[2]" foreach f (${list}) set f_tmp = `echo "$f" | sed "s/[0-9]/*/g"` echo "$f_tmp" end But it cannot work. Someone can help me this issue?
I have input list:
adr
adr
xadr
I want my output is: adr[*]
adr[*]
xadr[*]
#! /bin/csh -fv
set list = "adr adr xadr"
foreach f (${list})
set f_tmp = echo "$f" | sed "s/[0-9]/*/g"
echo "$f_tmp"
end
But it cannot work.
Someone can help me this issue?
ltdh
(1 rep)
Nov 7, 2023, 03:13 PM
• Last activity: Nov 7, 2023, 03:24 PM
0
votes
1
answers
54
views
How can wildcard expansion create duplicates?
I have a directory with an absurd number of files, which makes this nigh impossible to understand by inspection. But here's the situation: cp giant_folder/pre* myfolder It's crunching along and starts generating warnings like: cp: warning: source file 'giant_folder/pre1234.txt' specified more than o...
I have a directory with an absurd number of files, which makes this nigh impossible to understand by inspection. But here's the situation:
cp giant_folder/pre* myfolder
It's crunching along and starts generating warnings like:
cp: warning: source file 'giant_folder/pre1234.txt' specified more than once
How can this happen?
Mastiff
(101 rep)
Oct 31, 2023, 09:44 PM
• Last activity: Oct 31, 2023, 11:24 PM
1
votes
1
answers
1591
views
csh: redirecting output from foreach
In csh: How do I redirect the output from a `foreach`-loop to a pipe? This works but uses a temp file: set tmpfile=/tmp/file true > $tmpfile foreach v (`set | awk -e '{print $1}' |grep -v prompt2`); eval if'($?'$v' && ${#'$v'} > $tmpfile eval if'($?'$v' && ${#'$v'} > 1) echo array'$v'="$'$v'"' >> $t...
In csh: How do I redirect the output from a
foreach
-loop to a pipe?
This works but uses a temp file:
set tmpfile=/tmp/file
true > $tmpfile
foreach v (set | awk -e '{print $1}' |grep -v prompt2
);
eval if'($?'$v' && ${#'$v'} > $tmpfile
eval if'($?'$v' && ${#'$v'} > 1) echo array'$v'="$'$v'"' >> $tmpfile
end
cat $tmpfile | parallel --shellquote | perl -pe 's/^scalar(\S+).=/set $1=/ or s/^array(\S+).=(.*)/set $1=($2)/;'
I would like to get rid of the temp file and use a pipe instead. So something like this (does not work):
( foreach v (set | awk -e '{print $1}' |grep -v prompt2
);
eval if'($?'$v' && ${#'$v'} 1) echo array'$v'="$'$v'"'
end ) | parallel --shellquote | perl -pe 's/^scalar(\S+).=/set $1=/ or s/^array(\S+).=(.*)/set $1=($2)/;'
Ole Tange
(37348 rep)
Oct 4, 2015, 02:32 PM
• Last activity: Oct 31, 2023, 08:34 PM
0
votes
1
answers
1174
views
pipe into if then in csh/tcsh
I would like to have a csh script to test a variable between two pipes. For example (the incoming resembles a json file but without the newlines and indentations): set debug = 1 cat test.inp | if ($debug) then (jq '.response' | tee test2.json) else python -m json.tool endif > test.output The idea is...
I would like to have a csh script to test a variable between two pipes. For example (the incoming resembles a json file but without the newlines and indentations):
set debug = 1
cat test.inp | if ($debug) then (jq '.response' | tee test2.json) else python -m json.tool endif > test.output
The idea is that whatever the value of the variable debug, the output is saved in
test.output
. But the way I wrote this leads to the error:
> if: Improper then.
Is there any way to do this in csh/tcsh (as there seems to be in sh/bash)?
gammarayon
(1 rep)
Dec 30, 2019, 02:02 PM
• Last activity: Oct 30, 2023, 10:03 PM
0
votes
1
answers
160
views
C-Shell - stripping wildcards from user input
I am trying to strip wildcards from user input text in a c-shell script. I realize that the shell automatically expands all wildcards prior to storing the data. Is there a way to isolate the non-wildcard portion of user input? I also realize that c-shell is not the best shell for scripting. Unfortun...
I am trying to strip wildcards from user input text in a c-shell script.
I realize that the shell automatically expands all wildcards prior to storing the data.
Is there a way to isolate the non-wildcard portion of user input?
I also realize that c-shell is not the best shell for scripting. Unfortunately, the script is already written and I'm merely modifying.
Eric
(1 rep)
Oct 12, 2023, 05:43 PM
• Last activity: Oct 25, 2023, 05:06 PM
0
votes
1
answers
281
views
Calling a script from within csh with output redirection
What I would want: #!/bin/csh # call /myscriptpath/myscript.any and redirect 2>&1 and get retval and output set my_msg = `/myscriptpath/myscript.any` set my_ret = `echo $?` - How to capture the exit code from myscript.any? - How to capture the message from myscript.any, if possible? /myscriptpath/my...
What I would want:
#!/bin/csh
# call /myscriptpath/myscript.any and redirect 2>&1 and get retval and output
set my_msg =
/myscriptpath/myscript.any
set my_ret = echo $?
- How to capture the exit code from myscript.any?
- How to capture the message from myscript.any, if possible?
/myscriptpath/myscript.any This works as expected called from bash command line.
paulj
(238 rep)
Sep 21, 2023, 03:19 PM
• Last activity: Oct 3, 2023, 06:15 PM
0
votes
1
answers
229
views
When logging into a UNIX/Linux box, which profile scripts are executed?
When logging into a UNIX/Linux box, which profile scripts are executed? Typically there are several different profile scripts that set the $PATH variable and other aspects of the user's environment. However in most user's I've seen, they have .cshrc for CSH, .bashrc for bash, kshrc for ksh, etc.. Do...
When logging into a UNIX/Linux box, which profile scripts are executed?
Typically there are several different profile scripts that set the $PATH variable and other aspects of the user's environment. However in most user's I've seen, they have .cshrc for CSH, .bashrc for bash, kshrc for ksh, etc..
Do they all run upon login?
Is it based on the user's default shell?
How does the login script mechanism work?
For example when using su - which script would run?
drewhouses
(1 rep)
Aug 17, 2023, 07:08 PM
• Last activity: Aug 17, 2023, 10:13 PM
2
votes
1
answers
296
views
What does \!^ in csh alias do
Note: my shell is csh An ex-co-worker gave me the following command to put in my `.cshrc`: `alias bastion 'ssh -L \!^\: @ '` Note that what is in between are actual values. Now when I run this on my shell, I get the following error: `Bad ! arg selector.` I've been searching the web for similar uses...
Note: my shell is csh
An ex-co-worker gave me the following command to put in my
.cshrc
:
alias bastion 'ssh -L \!^\: @'
Note that what is in between are actual values.
Now when I run this on my shell, I get the following error: Bad ! arg selector.
I've been searching the web for similar uses of ssh -L
but I haven't found an example that uses this syntax of using the \!^\
in front of the :
.
Any idea what this command is actually trying to do and why it's not working?
Simon
(137 rep)
Jul 28, 2023, 07:13 PM
• Last activity: Jul 28, 2023, 10:15 PM
0
votes
1
answers
615
views
Behaviour of single and double quotes depending on shell
I've been scratching my head for quite some time with this.... Inspired by [this answer][1], I'm trying to run 'ack' and to find either a single quote or a double quote in source files. Doing this in **bash** perfectly works: `ack --cpp "['\"]"` But doing the same in **tcsh** gives me: `Unmatched "....
I've been scratching my head for quite some time with this....
Inspired by this answer , I'm trying to run 'ack' and to find either a single quote or a double quote in source files.
Doing this in **bash** perfectly works:
ack --cpp "['\"]"
But doing the same in **tcsh** gives me: Unmatched ".
One of the alternatives I have tried is to essentially swap the single and double quotes, leading to ack --cpp '[\'"]'
. But I'm still getting the same Unmatched ".
No matter what I try, I don't seem to be able to get the wanted behaviour in tcsh.
Any suggestions ?
DaveC
(1 rep)
Sep 2, 2021, 01:48 AM
• Last activity: Jul 20, 2023, 02:33 PM
Showing page 1 of 20 total questions