using 'watch' on an alias in .bashrc
Hi,
I have a line in ~.bashrc thus: alias temp='cat /proc/acpi/thermal_zone/THM0/temperature' which works fine for giving me the cpu temp. but if I try 'watch temp' (without quotes) it spits up error messages. The watch man page is not actually very informative but does mention something about using sh -c, and the need for quotes with some examples. I found sh in /bin and it is a link to bash. I have tried various different quotes ie watch 'temp' watch "'temp'" etc but nothing has worked. It is not that big of a deal because watch cat/proc/acp..........etc works fine, but it would save some typing if I knew how to get watch temp to work. Thanks for any ideas, mark The error message is: Code:
mark@~/$ watch temp |
try connecting the 2 words with an underscore "_"
IE.......... Code:
watch_temp |
Thanks 320mb but it didn't work, gave me a command not found error.
Anybody have any other suggestions? mark |
The only suggestion I can make is tis:
1) You have not rebooted since you made the change to ~/.bashrc. 2) You have not logged out/in since making the change. 3) You did not run 'source ~/.bashrc' after making the change. 4) You're still working in the same shell instance in which you made the change to .bashrc, and bash doesn't know about it yet. Do any one of the first three steps to reload .bashrc (step three is the easiest to apply), then try again. |
Thanks Bigrigdriver, but that is not it.
Typing temp in a terminal works fine, the alias in ~/.bashrc produces a figure for the cpu temperature. The problem is that I cannot watch the command. I am moving room fans around and I want to see which position causes the temperature to drop the fastest, hence having the temp alias run every two seconds will be very useful. Thanks for trying though, anybody have any more ideas? mark |
OK, try this then. Instead of trying to use an alias in .bashrc, make a small bash script to run the command. Something like:
#!/bin/bash watch 'cat /proc/acpi/thermal_zone/THM0/temperature' Give the script a name (watchtemp.sh, or whatever you prefer) and make it executable. Then run watch from the script. If one of your objectives is to save some typing, that'll do it. |
Yes, because the word 'temp' is passed to 'sh -c', aliases will not work. Although 'sh' is in fact bash, bash tries to be compatible with the old 'sh' command. Writing a script is your best bet.
[EDIT: I'm wrong. See below.] |
Quote:
And I have no earthly ides why anyone would tell you to put an underscore between a command and a variable/value, etc? Of course its going to give you a command not found! :rolleyes: |
Well... what you can do is put
Code:
alias watch = 'watch ' Sorry if this seems to totally contradict my last post. :) Actually, I've tried it now, and sh (that is, bash acting as sh) can in fact use aliases, if you tell it to. Well, you learn something new every day. Of course, I'd still recommend writing a script. |
Thanks everybody,
Bigrigdriver, that little script is just what I needed. Cheers, mark |
Hello,
Question is a bit old now, but in case someone's still looking for another solution -> might be fixed by adding watch in another alias : Code:
alias tempwatch="watch 'cat /proc/acpi/thermal_zone/THM0/temperature'" |
Welcome to LQ, Nicolas!
11 year old necro post! :) |
All times are GMT -5. The time now is 02:13 PM. |