Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
sh: line 1: temp: command not found
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.
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?
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.]
Last edited by Tim Retout; 01-02-2005 at 06:32 PM.
Originally posted by Tim Retout 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.
Yes, that is correct. You can't make a command understand an alias. Writing a script with the path to the /proc file and such should work just fine.
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!
alias watch = 'watch '
alias temp='cat /proc/some/file'
into .bashrc and then run 'watch temp'. But it's a bit fiddly. Only useful if there's more than one thing you want to watch, then you can throw in five or six aliases and run 'watch thing1', 'watch thing2', etc...
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.
Last edited by Tim Retout; 01-02-2005 at 06:35 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.