history -c in shell file does not work
Hi
I want to write a script which deletes the shell history.(ie) i want to execute the command "history -c" through a shell file.I have put the command history -c in the shell file and made the shell file to have execute permissions(chmod +x).But this is not working ,Can anyone point the error. Thanks in advance. |
This is because it is not executed in the current shell. A shell script looks like this (Assume its name is script.sh)
Quote:
The first line causes a new shell to be spawn. The commands in the file are executed in that shell. Hence it does not clear the history from your current shell. To circumvent this, run the script as shown below source ./script.sh |
Thanks it works,
Is there a way to execute the script like a normal script, without using the source program. |
Quote:
|
Quote:
This is how I clear my shell history and when you log back in, you'll have a fresh history to start with. Hope this helps. |
Use an alias or a function instead of writing a script for such simple task. That way it will be ran inside the context of the current shell.
|
All times are GMT -5. The time now is 06:49 AM. |