LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 03-02-2014, 09:13 PM   #1
BMan8577
Member
 
Registered: Apr 2011
Posts: 73

Rep: Reputation: 0
Question How to display amount of time the shell waits for user input...


I used the command TMOUT=10 for example. This is a Red Hat Shell Scripting course. I was wondering if it is supposed to execute any commands. Here are the specifications for the assignment and I will provide the commands I tried using.

1. "Display the amount of time the shell will wait for user input before the current shell is terminated using a shell variable."

2. "Set the previous variable to 120."

3. "Display the amount of time the shell will wait for user input before the current shell is terminated using a shell variable."

4. "Set the previous variable to 0."

The command I used for the script is:
TMOUT=10
export TMOUT=0
$TMOUT

And repeated the process for steps 2 and 3. When I run the command though I get an error unless I echo the command. Am I using the wrong command? Thanks.

Last edited by BMan8577; 03-02-2014 at 09:17 PM.
 
Old 03-03-2014, 12:47 AM   #2
rabbit2345
Member
 
Registered: Apr 2007
Location: 中国上海
Distribution: openSUSE 11.3
Posts: 369

Rep: Reputation: 40
Hi,

I'm not quite sure why you're setting TMOUT to 10 then immediately to 0, but the net effect is you trying to run a command called '0'. I'll explain.

Quote:
Originally Posted by BMan8577 View Post
TMOUT=10
You set the variable TMOUT to 10.

Quote:
Originally Posted by BMan8577 View Post
export TMOUT=0
You exported the variable TMOUT to children processes, and set it to 0. When you "export" a variable, you make it visible to processes that the current shell will spawn. More details here: http://stackoverflow.com/questions/7...export-command

In the context of a single shell with no children spawning, "export" has no real effect.

Quote:
Originally Posted by BMan8577 View Post
$TMOUT
This is where the error comes from. Shells (at least, bash will) will directly replace the $TMOUT portion with its value blindly before parsing. Since this is the first and only argument on the line, it will try to run it as a command/function.

Code:
% TMOUT=0
% $TMOUT       <-- gets replaced by 0 before processing the command.
% 0            <-- this is what the shell sees, which is invalid since there's no command called 0.
bash: 0: command not found
%
So, to recall a variable's value and print it out, you would just have to use echo first.

Code:
% TMOUT=0
% echo $TMOUT       <-- gets replaced by 0 before processing the command.
% echo 0            <-- this is what the shell sees, which is OK this time.
0
%

If you need additional help, there's no shortage of bash guides online. My personal favorite is this: http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html


-rabbit
 
  


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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Kernel Module waits for user input Abid Malik Linux - Kernel 4 03-25-2011 11:50 AM
Make most amount of Linux users in least amount of time studpenguin General 24 02-02-2007 04:42 PM
an open source program that only gives the user a certain amount of time to input? dr_zayus69 Programming 4 05-22-2005 11:56 PM


All times are GMT -5. The time now is 06:45 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration