Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

5 votes
4 answers
4935 views
change prompt formatting based on cwd
I use tcsh. I'd like to have my prompt formatting (coloring/highlighting) change based on the directory I'm in, or other critical aspects of my environment. I'm not enough of a shell hacker to know how to do this. Ownership of Current Directory ------------------------------ If I'm in one of "my" di...
I use tcsh. I'd like to have my prompt formatting (coloring/highlighting) change based on the directory I'm in, or other critical aspects of my environment. I'm not enough of a shell hacker to know how to do this. Ownership of Current Directory ------------------------------ If I'm in one of "my" directories (i.e., I am owner of the current working directory), then it should have normal appearance. But if I'm in someone else's directory (I do a lot of support and cd to others' working areas), then I want the prompt to look clearly different. This is to remind me to not type impolite commands in others' directories. (think make clobber or p4 sync, etc.) Critical Environment Variable Setting ------------------------------------- Another important piece of information for my environment is whether a certain environment variable is set, call it SWDEV. If SWDEV is not set, then my scripts and flows come from their default location. But if this variable is set, then it's taken as a new root location for my scripts and flows, with behaviors changing according to the scripts at that location. It's important to be reminded of the setting of this variable, lest I expect "normal" behavior but instead absentmindedly run code from the new location.
Winston Smith (838 rep)
May 15, 2013, 12:08 AM • Last activity: May 26, 2025, 02:09 PM
5 votes
3 answers
2089 views
find with -prune leaves pruned directory names
I constructed the following find command: find ./ \( -path "*work*" -o -path "*ncvlog_lib*" \) -prune -o -type f -not -name "*.wlf" -not -name "*.vcd" -not -name "*.sim" -not -name "*vcs*" The command is invoked in a single line. I broke the line here for readability. The only trouble is that it pri...
I constructed the following find command: find ./ \( -path "*work*" -o -path "*ncvlog_lib*" \) -prune -o -type f -not -name "*.wlf" -not -name "*.vcd" -not -name "*.sim" -not -name "*vcs*" The command is invoked in a single line. I broke the line here for readability. The only trouble is that it prints the pruned directory names, despite providing the -type f argument. Sample output: ./cdl2verilog_files/test_synth/work ./cdl2verilog_files/test_synth/some_file1.txt ./cdl2verilog_files/test_synth/something_else.txt ./cdl2verilog_files/test_synth/another_file.v work is a directory. Its contents are not included in the output, so the prune works as needed. However, the directory itself is printed out. I can't seem to find a solution for this. Any thoughts? I am using tcsh by the way.
ocmob (53 rep)
Feb 21, 2018, 09:52 AM • Last activity: May 6, 2025, 12:56 PM
2 votes
3 answers
5954 views
loop through file by row in tcsh
This is a very similar question to [How to loop over the lines of a file?](https://unix.stackexchange.com/questions/7011/how-to-loop-over-the-lines-of-a-file). I have a file with rows with _n_ fields, separated by spaces. I want to loop through this file by row, and use the set the fields as variabl...
This is a very similar question to [How to loop over the lines of a file?](https://unix.stackexchange.com/questions/7011/how-to-loop-over-the-lines-of-a-file) . I have a file with rows with _n_ fields, separated by spaces. I want to loop through this file by row, and use the set the fields as variables, for use in calling information from a different file. So, for example, my file looks like this:
A B C
D E F
H I J
K L M
I'd like to loop thru each line and set the variables to be the fields: foreach i ( cat file ) set 1st = $i; set 2nd = $i; set 3rd = $i end Right now, my shell is using spaces to separate the fields, and this means I can't set the 3 variables in each row. Were I to echo each $i - I'd see this: A B C D .... I'd like to know how to control my loop by using only the new lines as the separators. Here's what I really want to achieve. I want to grep rows in file A which contain 3 different values, all of which appear as space separated elements in the rows of file B. My plan was to loop thru each line in file B, setting variables for each of the (space separated) elements in that row of B, and then make use of these 3 elements. And then repeat for the next row of B. But my loop fails because it doesn't see the rows in file B. It only sees ALL the space separated elements, with no recognition of their grouping into rows of 3 elements. I hope this isn't confusing
ZakS (315 rep)
Nov 21, 2021, 01:24 PM • Last activity: Apr 27, 2025, 01:08 PM
2 votes
1 answers
441 views
Enabling command hashing in tcsh
It seems command hashing is disabled by default in our `tcsh` environment, and I'm not permitted to get it enabled across the board. Instead I'm looking to enable command hashing within individual scripts, all of which contain while loops, so I'd expect the first iteration to loop through all the pa...
It seems command hashing is disabled by default in our tcsh environment, and I'm not permitted to get it enabled across the board. Instead I'm looking to enable command hashing within individual scripts, all of which contain while loops, so I'd expect the first iteration to loop through all the paths defined in $PATH and subsequent iterations to hit the exact path from the internal hash table. The purpose is to reduce the number of failed execve calls captured by the audit service. First question, is there a command similar to hash in tcsh to output the internal hash table? Hashstat doesn't appear to work, it doesn't output anything on the prompt, perhaps because hashing is disabled? When I did get it to print something, it printed only the number and size of hash buckets, not any specific commands. Main question, I've tried adding rehash to the beginning of the script, which has helped reduce the number of execve calls per command from ~5 to ~2 (even on the first iteration). For some reason, it still always tries to run commands from /sbin first. Any suggestions on what to check to see why after running rehash it still tries to execute a command from an invalid path, or is there an alternative way to enable command hashing from within a script? Side question, bash on the other hand still manages to hit the correct path even with the hash table disabled. Any idea how it does this without command hashing? Lastly, strace hasn't captured the failed execve calls captured by audit. I've tried simple strace sleep, and strace -f -e trace=execve sleep, both essentially just showing the correct entry, but not the failed ones: execve("/bin/sleep", ["sleep"], 0x7ffe0d773ff8 /* 32 vars */) = 0
Maikol (164 rep)
Mar 17, 2024, 10:38 PM • Last activity: Apr 17, 2025, 09:32 AM
2 votes
2 answers
191 views
Bash equivalent of tcsh M-$?
Way back while studying I used tcsh as my main shell and it had this nifty feature of being able to correct a misspelled command name by pressing Escape - $ which would change e.g. `bsah` to `bash` Now I needed it (apparently kustomize is not keyboard friendly) but could not recall ever having seen...
Way back while studying I used tcsh as my main shell and it had this nifty feature of being able to correct a misspelled command name by pressing Escape-$ which would change e.g. bsah to bash Now I needed it (apparently kustomize is not keyboard friendly) but could not recall ever having seen this in bash. Can bash do this and if so how?
Thorbjørn Ravn Andersen (1064 rep)
May 19, 2023, 01:11 PM • Last activity: Apr 15, 2025, 01:38 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
4 votes
1 answers
232 views
Missing "}" when running activate on tcsh
I am trying to set up a virtualenv on my tcsh and when I run a bash shell I am able to run this command perfectly source ./venv/bin/activate But when I run this same command from a tcsh I get this error message missing "}" . How can I fix it ?
I am trying to set up a virtualenv on my tcsh and when I run a bash shell I am able to run this command perfectly source ./venv/bin/activate But when I run this same command from a tcsh I get this error message missing "}" . How can I fix it ?
gansub (143 rep)
Jan 13, 2025, 08:48 AM • Last activity: Jan 13, 2025, 09:21 AM
0 votes
2 answers
1678 views
for loop in FreeBSD (pfSense) doesn't work
I've just noticed that the same code for `for loop` in bash doesn't work in FreeBSD wolf@linux:~$ echo $SHELL /bin/bash wolf@linux:~$ wolf@linux:~$ for i in {1..3}; do echo $i; done 1 2 3 wolf@linux:~$ Is there any alternative for this? [2.5.0-RELEASE][admin@pfSense]/root: echo $SHELL /etc/rc.initia...
I've just noticed that the same code for for loop in bash doesn't work in FreeBSD wolf@linux:~$ echo $SHELL /bin/bash wolf@linux:~$ wolf@linux:~$ for i in {1..3}; do echo $i; done 1 2 3 wolf@linux:~$ Is there any alternative for this? [2.5.0-RELEASE][admin@pfSense]/root: echo $SHELL /etc/rc.initial [2.5.0-RELEASE][admin@pfSense]/root: [2.5.0-RELEASE][admin@pfSense]/root: for i in {1..3}; do echo $i; done for: Command not found. i: Undefined variable. [2.5.0-RELEASE][admin@pfSense]/root:
Wolf (1741 rep)
Mar 7, 2021, 12:11 PM • Last activity: Oct 17, 2024, 05:05 AM
0 votes
1 answers
45 views
tcsh piping ONLY stderr to null leaving stdout alone
running a `tcsh` in RHEL-8.10. doing a `grep -l *` I get a bunch of `Is a directory` responses. in bash I would do `grep -l * 2>/dev/null` to suppress that. What is the equivalent syntax in tcsh ?
running a tcsh in RHEL-8.10. doing a grep -l * I get a bunch of Is a directory responses. in bash I would do grep -l * 2>/dev/null to suppress that. What is the equivalent syntax in tcsh ?
ron (8647 rep)
Jul 18, 2024, 07:53 PM • Last activity: Jul 18, 2024, 08:02 PM
2 votes
1 answers
204 views
less command stops working after setting terminal title in .tcshrc
After I add the following command to my `~/.tcshrc`: echo "\033]0;${PROJECT_NAME}\007" The `less` command in a new `gnome-terminal` stops working properly. But `more` command is not affected. This is what I see when trying to run `less` command: less log ESC]0;MYPROJ^G log (END)
After I add the following command to my ~/.tcshrc: echo "\033]0;${PROJECT_NAME}\007" The less command in a new gnome-terminal stops working properly. But more command is not affected. This is what I see when trying to run less command: less log ESC]0;MYPROJ^G log (END)
Roman Kaganovich (171 rep)
Jan 30, 2018, 08:23 AM • Last activity: Jun 18, 2024, 04: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
3 votes
1 answers
589 views
tcsh: Handle spaces in arguments when passing on to another command
I wrote a script that needs to call a command and pass on arguments. My script has its own parameters but some need to be passed through. This fails when arguments to my script have spaces in them. Here is the script, reduced to the passing on of arguments: #!/bin/tcsh set passthrough = "" checkpara...
I wrote a script that needs to call a command and pass on arguments. My script has its own parameters but some need to be passed through. This fails when arguments to my script have spaces in them. Here is the script, reduced to the passing on of arguments: #!/bin/tcsh set passthrough = "" checkparams: if ( $# > 0 ) then # Add the argument to passthrough, ensuring spaces are preserved set passthrough = "$passthrough '${1:q}'" # Show what has been added in one go echo "Added passthrough: '${1:q}'" shift goto checkparams endif # Using echo here instead of the real command echo $passthrough Calling this script shows the problem: user@host:/home/user/bin -> ./test_preserve_passthrough a "b b" c Added passthrough: 'a' Added passthrough: 'b b' Added passthrough: 'c' 'a' 'b b' 'c' As you can see, the 4 spaces between the 'b's disappear. In fact, when I pass a single argument with spaces in it, echo receives not one argument but many as the single string will be broken up by its spaces " ". I tried many ways of quoting (single, double, {$x:q}) and combinations but still cannot preserve the spaces in any way. When an argument is given to my script like a (TAB-completed) filename this\ \ is\ a\ file\ with\ spaces\ in\ its\ name the backslashes need to be removed, and in the above example with a "b b" c three arguments need to be passed on unchanged: a and b b and c.
Ned64 (9256 rep)
May 19, 2024, 04:42 PM • Last activity: May 20, 2024, 10:26 AM
6 votes
3 answers
5672 views
tcsh shortcut to move the cursor back to previous space
I'm looking for a keyboard shortcut in `tcsh` to move the cursor back to the previous blank: not ESC + B which takes me back one word (for instance, in a path argument, to the previous path component) - I want to get to previous space or start of current path.
I'm looking for a keyboard shortcut in tcsh to move the cursor back to the previous blank: not ESC+B which takes me back one word (for instance, in a path argument, to the previous path component) - I want to get to previous space or start of current path.
haimon (63 rep)
May 7, 2013, 02:41 PM • Last activity: May 10, 2024, 07:42 PM
0 votes
1 answers
163 views
TCSH tab auto complete with the part of current typed command
I am trying to write my own complete for a command. The completion needs to use a portion of the typed command to for a path search. I am trying to get the following behavior When I write `my_commad -ws my_ws -t[TAB]` a list of folders under my_ws/tests appears as a list of completion I couldn't fig...
I am trying to write my own complete for a command. The completion needs to use a portion of the typed command to for a path search. I am trying to get the following behavior When I write my_commad -ws my_ws -t[TAB] a list of folders under my_ws/tests appears as a list of completion I couldn't figure out how to break it I tried the following, but failed because of quotes problem, I guess
complete my_command 'n@-t@echo $COMMAND_LINE | perl -ne '/-ws (\w+)/; print $1'@'
Dan Messer (3 rep)
Mar 23, 2024, 07:22 PM • Last activity: Mar 24, 2024, 02:18 PM
1 votes
1 answers
169 views
Force tcsh to check whether command exist in the path before attempting to execute it
I've noticed that tcsh, regardless of whether "-f" flag is passed on the shebang line, will iterate through $PATH, and try to execute the command from that path until the command is found. Whereas bash first checks whether the command is present in that location. This tcsh behaviour leads to a lot o...
I've noticed that tcsh, regardless of whether "-f" flag is passed on the shebang line, will iterate through $PATH, and try to execute the command from that path until the command is found. Whereas bash first checks whether the command is present in that location. This tcsh behaviour leads to a lot of failed entries in the audit logs as our audit has been configured to capture execve system calls. For instance when sleep is called from within a tcsh script, one of the failed audit entries shows it tried to run sleep with absolute path: "/usr/local/bin/sleep". type=SYSCALL msg=audit(1710330471.326:37838): arch=c000003e syscall=59 success=no exit=-2 a0=2601590 a1=261e010 a2=261d110 a3=7ffdc4a409e0 items=1 ppid=8930 pid=8938 auid=1011478343 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts1 ses=863 comm="csh_test.sh" exe="/usr/bin/tcsh" subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key="non_sys_execs" type=CWD msg=audit(1710330471.326:37838): cwd="/tmp" type=PATH msg=audit(1710330471.326:37838): item=0 name="/usr/local/bin/sleep" objtype=UNKNOWN cap_fp=0000000000000000 cap_fi=0000000000000000 cap_fe=0 cap_fver=0 type=PROCTITLE msg=audit(1710330471.326:37838): proctitle=2F62696E2F637368002E2F6373685F746573742E7368 Strace shows bash stats first, before attempting an access:
stat("/usr/local/bin/sleep", 0x7ffdd8de5630) = -1 ENOENT (No such file or directory)
stat("/usr/local/sbin/sleep", 0x7ffdd8de5630) = -1 ENOENT (No such file or directory)
stat("/sbin/sleep", 0x7ffdd8de5630)     = -1 ENOENT (No such file or directory)
stat("/bin/sleep", {st_mode=S_IFREG|0755, st_size=33128, ...}) = 0
The order in which it traverses the paths matches the order the paths are defined in $PATH. Unfortunately changing the order around on all our servers will not be possible, also it's unclear what the implications would be of putting /bin/ ahead of /usr/local/bin etc. Whilst, I doubt it, but just in case, is there perhaps some runtime or install configuration to force tcsh to stat first just like bash does? Is there anything else that could be done at all to avoid these failures (apart from amending scripts to use the full path or filtering out these execve calls from audit capture)?
Maikol (164 rep)
Mar 15, 2024, 10:45 AM • Last activity: Mar 20, 2024, 07:17 AM
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
16 votes
2 answers
22029 views
the usage of < /dev/null & in the command line
I tried to run an example java program using the following command line. However, I do not know what is the trailing part ` & log < /dev/null &
I tried to run an example java program using the following command line. However, I do not know what is the trailing part `& log < /dev/null &
user297850 (841 rep)
Dec 30, 2011, 02:51 AM • Last activity: Dec 27, 2023, 07:13 PM
0 votes
0 answers
140 views
linux tcsh scripting question
I am writing a linux `tcsh` script to check the syntax of a command argument to insure its correct before the command executes. Out of the 9 fields I have saved as variables in the script, I am able to get 7 of them checked. I only have 2 remaining and they are both confounding me with the same issu...
I am writing a linux tcsh script to check the syntax of a command argument to insure its correct before the command executes.
Out of the 9 fields I have saved as variables in the script, I am able to get 7 of them checked. I only have 2 remaining and they are both confounding me with the same issues.
The first one is a check of "tco14" or "tc14a" these are 2 examples of the same field I need to have the script check.
The preceding 2 examples will always break down like this:
"tc" will always begin this argument followed by the next 2 positions which should be numbers between 1-9 then the final position which can be either a number or a letter. In bash I had it working with these lines: # Check the seventh field check_field "$var7" 'TC([0-9]{3}|[0-9]{2}[a-zA-Z])$' "Field 7 is not valid:" 7 That script used arrays in getting the cheeck accomplished, HOWEVER as I found out in tcsh it doesnt play nice with ALOT of bash scripting. So Ive tried the following in tcsh: # Check if field7 matches the specified format set valid_field7 = expr "$field7" : '^tc[0-9]\{1,3\}[a-zA-Z0-9]$' if ($valid_field7 == 0) then echo "${RED}Error: Invalid syntax for field7. Must start with 'tc' followed by 2 digits and end with a digit or a letter.${NC}" exit 1 endif This almost works but it also passes the check with tc12 which it shouldnt. Again this field of the argument needs 3 character the first 2 are numbers and the last one is a number or a letter. Reference following lines for possibly a better understanding: - First Position = t - Second Position = c - Third Position = number between 0-9 - Fourth Position = number between 0-9 - Fifth Position = a letter or a number between 0-9
Brian (5 rep)
Nov 22, 2023, 01:05 AM • Last activity: Nov 30, 2023, 08:29 PM
11 votes
4 answers
4135 views
bash readline: Key binding that executes an external command
(Background: I'm a long-time tcsh user, gradually transitioning to bash, and trying to find equivalents for some useful tcsh-specific features.) In tcsh, I can define a key binding that executes an external command. For example, given: bindkey -c ^Gu uptime I can type "Control-G u" in tcsh, and it w...
(Background: I'm a long-time tcsh user, gradually transitioning to bash, and trying to find equivalents for some useful tcsh-specific features.) In tcsh, I can define a key binding that executes an external command. For example, given: bindkey -c ^Gu uptime I can type "Control-G u" in tcsh, and it will execute the uptime command. I don't have to type Enter, the command doesn't appear in my history, and I can do it in the middle of an input line (I find the latter particularly useful for certain commands). bash has a similar key binding mechanism via the GNU readline library, with bindings specified in $HOME/.inputrc (or elsewhere). But after reading the info readline documentation, I don't see a way for a key binding to execute an external command. The closest thing I've figured out is to add something like this to my .inputrc file: "\C-gu": "uptime\n" but that doesn't execute the command; rather, it acts as if I had typed uptime followed by the Enter key. The command appears in my history (that's ok), and it works only on an empty line; if I type "echo control-Gu", then it prints uptime rather than executing the command. Another minor drawback is that the binding affects other commands that use GNU readline, such as the Perl debugger. Is there a way to simulate the effect of tcsh's bindkey -c in bash, by mapping a key sequence to the execution of a specified external command? If it matters, I'm using bash 4.2.24 on Ubuntu 12.04 beta 2.
Keith Thompson (22970 rep)
Apr 19, 2012, 10:00 PM • Last activity: Nov 2, 2023, 03:00 AM
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
Showing page 1 of 20 total questions