LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 01-01-2005, 12:30 AM   #1
slackist
Member
 
Registered: Feb 2004
Location: Phuket
Distribution: Slackware 14.1 and Slackware Arm
Posts: 478

Rep: Reputation: 41
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
sh: line 1: temp: command not found
 
Old 01-01-2005, 01:24 AM   #2
320mb
Senior Member
 
Registered: Nov 2002
Location: pikes peak
Distribution: Slackware, LFS
Posts: 2,577

Rep: Reputation: 48
try connecting the 2 words with an underscore "_"

IE..........
Code:
watch_temp
 
Old 01-01-2005, 04:02 AM   #3
slackist
Member
 
Registered: Feb 2004
Location: Phuket
Distribution: Slackware 14.1 and Slackware Arm
Posts: 478

Original Poster
Rep: Reputation: 41
Thanks 320mb but it didn't work, gave me a command not found error.


Anybody have any other suggestions?

mark

Last edited by slackist; 01-01-2005 at 04:05 AM.
 
Old 01-01-2005, 09:58 AM   #4
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,889

Rep: Reputation: 351Reputation: 351Reputation: 351Reputation: 351
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.
 
Old 01-01-2005, 11:09 PM   #5
slackist
Member
 
Registered: Feb 2004
Location: Phuket
Distribution: Slackware 14.1 and Slackware Arm
Posts: 478

Original Poster
Rep: Reputation: 41
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
 
Old 01-02-2005, 11:59 AM   #6
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,889

Rep: Reputation: 351Reputation: 351Reputation: 351Reputation: 351
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.
 
Old 01-02-2005, 04:35 PM   #7
Tim Retout
LQ Newbie
 
Registered: Dec 2004
Location: UK
Distribution: Debian
Posts: 21

Rep: Reputation: 15
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.
 
Old 01-02-2005, 05:01 PM   #8
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 235Reputation: 235Reputation: 235
Quote:
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!
 
Old 01-02-2005, 06:13 PM   #9
Tim Retout
LQ Newbie
 
Registered: Dec 2004
Location: UK
Distribution: Debian
Posts: 21

Rep: Reputation: 15
Well... what you can do is put
Code:
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.
 
Old 01-03-2005, 12:52 AM   #10
slackist
Member
 
Registered: Feb 2004
Location: Phuket
Distribution: Slackware 14.1 and Slackware Arm
Posts: 478

Original Poster
Rep: Reputation: 41
Thanks everybody,

Bigrigdriver, that little script is just what I needed.

Cheers,

mark
 
Old 01-29-2016, 09:37 AM   #11
Nicolas Pineau
LQ Newbie
 
Registered: Jan 2016
Posts: 1

Rep: Reputation: Disabled
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'"
 
Old 01-29-2016, 01:09 PM   #12
Habitual
LQ Addict
 
Registered: Jan 2011
Posts: 8,361
Blog Entries: 11

Rep: Reputation: 2329Reputation: 2329Reputation: 2329Reputation: 2329Reputation: 2329Reputation: 2329Reputation: 2329Reputation: 2329Reputation: 2329Reputation: 2329Reputation: 2329
Welcome to LQ, Nicolas!

11 year old necro post!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
adding perm. alias to .bashrc Lleb_KCir Linux - General 7 12-09-2004 02:35 PM
making alias, can't find .bashrc file djgerbavore Slackware 10 07-23-2004 08:23 AM
My first alias in .bashrc...'apostrophes 'getting' in the way?' Baix Linux - Newbie 3 06-17-2004 02:36 PM
alias and .bashrc whaase Linux - General 3 11-02-2003 07:03 PM
alias and bashrc Haldir Linux - Newbie 3 06-14-2002 05:11 PM


All times are GMT -5. The time now is 06:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration