Solved Aliases executed while I open CShell.

Hello,
These are some of my aliases.
Bash:
alias auth_log tail -20 /var/log/auth.log

alias clean_err_log echo "" > /var/log/httpd-error.log
alias clean_acc_log echo "" > /var/log/httpd-access.log

I was suprised that my logs are empty after each shell start. I deleted cleaning aliases and my logs are not deleting anymore. So for me it looks like os is executing all aliases on shell start. What am I missing? Or is it a bug/feature ?? Can I make alias that executes only when I want?

Cheers.
 
Your commands are doing exactly what you told them to do:
set an alias called clean_err_log to the command echo "" and put whatever output is generated by creating that alias into a file called /var/log/httpd-error.log

You need some quotes:
Code:
alias clean_err_log 'echo "" > /var/log/httpd-error.log'
alias clean_acc_log 'echo "" > /var/log/httpd-access.log'
 
I think it should be (notice the "=" sign):

Code:
alias clean_err_log='echo "" > /var/log/httpd-error.log'
alias clean_acc_log='echo "" > /var/log/httpd-access.log'
 
I checked in both ways and seems that "=" doesn't change anything. work in CShell
Code:
alias clean_acc_log = 'echo "" > /var/log/httpd-access.log' works same as:
alias clean_acc_log 'echo "" > /var/log/httpd-access.log'

and

alias clean_acc_log = echo "" > /var/log/httpd-access.log
works same as
alias clean_acc_log echo "" > /var/log/httpd-access.log

set an alias called clean_err_log to the command echo "" and put whatever output is generated by creating that alias into a file called /var/log/httpd-error.log
Shell still stops reading for alias afer ">".
Thx anyway, it was worth to check.
 
Well I don't remember how I checked, but:

Code:
alias clean_err_log='echo "" > /var/log/httpd-error.log'

:~# clean_err_log
clean_err_log: Command not found.

alias clean_acc_log = 'echo "" > /var/log/httpd-access.log
:~ # clean_acc_log
=: Command not found.

These work properly:
Code:
alias clean_err_log 'echo "" > /var/log/httpd-error.log'
alias clean_acc_log 'echo "" > /var/log/httpd-access.log'

So I checked wrong for sure :p.

"=" makes that something doesn't work.
I have CShell, I chose bash formatting for code quote. I don't know other shells but seems it can be diffrence between Bash and CShell.

The most important is to have whole command in ' ', or it will execute (what can be used too).
 
Back
Top