Tcsh precmd weird question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Tcsh precmd weird question
# 1  
Old 02-27-2019
Tcsh precmd weird question

I encountered a weird question while using tcsh. I wrote a test script trying to control 'history' behavior as below,

Code:
set history=(1000 "%h\t%Y-%W-%D %P %R\n")
set savehist=(1000 merge)
alias precmd 'history -S;history -M'

I was hoping all the user's commands input in multiple terminals can be recorded to the history file without lose.
My script can worked well in RHEL 6 ( the default tcsh version is 6.17).
However, when I tested my script in RHEL 4/5 (tcsh version 6.13 / 6.14), the precmd alias resulted in command line in malfunction.
Whatever I input on the command line after running my script, it was just jumping to the newline, nothing happened.

I have no idea what went wrong. Does anybody have idea? Thanks.
# 2  
Old 02-27-2019
What does 'jumping to the newline' mean?
# 3  
Old 02-28-2019
Quote:
Originally Posted by Corona688
What does 'jumping to the newline' mean?
Sorry, I didn't describe it clearly.
I mean after running my script, I input any coomands and then press enter, it shows nothing. I can't even use exit command to close the terminal.
# 4  
Old 03-01-2019
I can reproduce this with tcsh 6.12. After
Code:
alias precmd 'history -S;history -M'

it only echos the typed commands, without running them.
Looks like a bug.
Try
Code:
alias postcmd 'history -S;history -M'

Doesn't this even make more sense?
This User Gave Thanks to MadeInGermany For This Post:
# 5  
Old 03-01-2019
Quote:
Originally Posted by MadeInGermany
I can reproduce this with tcsh 6.12. After
Code:
alias precmd 'history -S;history -M'

it only echos the typed commands, without running them.
Looks like a bug.
Try
Code:
alias postcmd 'history -S;history -M'

Doesn't this even make more sense?
Thank you for confirming this.
It seems like no workaround, does it?

I haven't tried postcmd, I ‘ll try this to see what happen. Thanks.
# 6  
Old 03-03-2019
I've tried postcmd, it works well. Thank you.
# 7  
Old 07-19-2019
Quote:
Originally Posted by bestard
I've tried postcmd, it works well. Thank you.
Just report my experiences using precmd and postcmd. Actually, I've had enough coping with tcsh bugs.
I'm now using tcsh 6.17.00 (Astron).
On account of precmd's bug, I used postcmd to do an alias command as below

Quote:
alias postcmd 'history -S;history -M'
It looked worked, but actually this alias caused while loop in a shell script worked erratically.
While I did a simple increment by 1 to a variable, it only looped once and finished.
It can be easily reproduced this bug.

My suggestion is using this two functions in precaution if you don't want to mess up with other built-in commands.
I've given up on the "history stuff" unless someone has a better solution.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Tcsh Problems with # and []

Hallo, I try to write a program which processes an input-file linewise. I created the following minimal example: hash-problem:#!/bin/tcsh foreach text ("`cat $1`") echo $text endUsually, it works as expected, but there are two problems: 1. If the argument of hash-problem has an... (3 Replies)
Discussion started by: DanielDD
3 Replies

2. Shell Programming and Scripting

Tcsh to sh

Dear all, I have piece of command from tcsh, which I would like to be in my .bashrc file. However, I am comletely blank about the tcsh commandline. if (-e ~/forum/dir/code.sh) then source ~/forum/dir/code.sh endif Any piece of suggestions how to convert it to sh way? Thank you emily (5 Replies)
Discussion started by: emily
5 Replies

3. Shell Programming and Scripting

tcsh help

Does anyone no way my .tcsh_history file is filling up with a bunch of crap?? It is filled with lines like: ! ls eccracrascratcd ! ls mecd /hchoo "cratch2/mecd /sch2/mecd /sh2/mecd /scratchcd /scratch2/mecd /scratcraecd /ls mo "ls" > ! ls eccratch2/mecd /sc/ls"d /scratch2/mecd histecho "ls" o... (2 Replies)
Discussion started by: Bic121
2 Replies

4. Shell Programming and Scripting

logging out in tcsh

Hi! I want to log out of the tcsh shell without updating the history? Thanks, Jack. (3 Replies)
Discussion started by: jacki
3 Replies

5. Shell Programming and Scripting

simple tcsh question using foreach

I want to search line-by-line for a string in a file, and I want to do this to a series of files in a directory. I'm doing this in tcsh This works fine to do the search: while read i; do grep $i file2; done <file1.txt This also works fine to read a directory: foreach file ('/bin/ls... (1 Reply)
Discussion started by: moldoverb
1 Replies

6. UNIX for Dummies Questions & Answers

help in tcsh

am working in tcsh while writing a script, what is diff between foll two starting line #!/bin/csh #!/bin/csh -f Also can I use the same line for script in tcsh or I have to necessarily use #!/bin/tcsh I guess even #!/bin/sh will also do. Kindly clarify (3 Replies)
Discussion started by: mahendrakamath
3 Replies

7. Shell Programming and Scripting

Help me with this tcsh script.!!!!

I need to write a tcsh script which would compare files in the two folders and then send me a mail saying which of the files are missing.For eg 1) I have this folder1 containing all the files which must land on folder2 on a daily basis. 2) If a file is present in folder1 but not in... (6 Replies)
Discussion started by: kumarsaravana_s
6 Replies

8. UNIX for Dummies Questions & Answers

Kind of weird question

I recently purchased a book titled Hacking: The Art of Exploitation. When I got it home I read the preface and found out that i shouldnt have bought it. It says the code examples in this book were done on an x86 based computer (I have a mac). Is there anything I can do to make my mac run similar to... (2 Replies)
Discussion started by: Cyberaxe
2 Replies

9. UNIX for Advanced & Expert Users

Weird Question

As in Windows we have Video memory and we can access it through C programs, do we have anything similar to that in Unix and similar operating systems. If we have some sort of Video memory in Unix flavours, then how can we access it through C programs. (4 Replies)
Discussion started by: rahulrathod
4 Replies

10. Shell Programming and Scripting

tcsh

I'm working on OpenOffice Localization; In that I need to work most of in 'tcsh' Since I have almost work till now in 'bash', I want to explore 'tcsh' much more .. An body suggest me a way ? books ? Thanks, :) (1 Reply)
Discussion started by: kartik
1 Replies
Login or Register to Ask a Question