LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 12-22-2005, 05:48 AM   #1
PDock
Member
 
Registered: Aug 2004
Distribution: Slack10 & curr. tried numerous
Posts: 189

Rep: Reputation: 37
Bash Script- command on exit


Is there a way to 'pre-fill' the command line when your bash script exits?

If your scripts contains a test like:
Code:
if [ ! -f /etc/HOSTNAME ]; then
clear
echo "You do not have a /etc/HOSTNAME file. You need to setup your network first!"
echo "Come back after setting up your network."
NEED COMMAND HERE=/sbin/netconfig
exit
fi
Such that after the script exits the command line would be prefilled with the 'variable' set by the script. ie
Code:
yourprompt# /sbin/netconfig
Note: I don't want the script to chain another script; just exit and prefill if possible.

thanks in advance
ppd
 
Old 12-22-2005, 06:06 AM   #2
heema
Senior Member
 
Registered: Sep 2003
Location: Egypt
Distribution: Arch
Posts: 1,528

Rep: Reputation: 47
sorry i am at work now so i am not infront of linux ;(

you could try something like this

Code:
if [ ! -f /etc/HOSTNAME ]; then
clear
echo "You do not have a /etc/HOSTNAME file. You need to setup your network first!"
echo "Come back after setting up your network."
xterm -e 'echo /sbin/netconfig' &
exit
fi
 
Old 12-22-2005, 03:44 PM   #3
alienDog
Member
 
Registered: Apr 2004
Location: Europe
Distribution: Debian, Slackware
Posts: 505

Rep: Reputation: 48
--edit--

sorry read it poorly, mine was not the answer to the question The above answer suggested by heema will of course not do the trick either. It will simply echo /sbin/netconfig on xterm and exit. As far as I know, there is no way. Why don't you just suggest running /sbin/netconfig from inside the script?

Last edited by alienDog; 12-22-2005 at 03:51 PM.
 
Old 12-22-2005, 05:48 PM   #4
PDock
Member
 
Registered: Aug 2004
Distribution: Slack10 & curr. tried numerous
Posts: 189

Original Poster
Rep: Reputation: 37
Thanks for the replies, if no one comes up with and answer; quess telling what to execute is only answer.
Hate to admit my age, and at my age can only half remember a DOS keypad keystroke key??? command that achieved what I am looking for in bash.

Again thanks
ppd
 
Old 12-22-2005, 08:04 PM   #5
alienDog
Member
 
Registered: Apr 2004
Location: Europe
Distribution: Debian, Slackware
Posts: 505

Rep: Reputation: 48
Of course you could offer to run the command for the user:

Code:
if [ ! -f /etc/HOSTNAME ]; then
clear
echo "You do not have a /etc/HOSTNAME file. You need to setup your network first!"
echo "Come back after setting up your network."
echo -en "\n Do you want to run /sbin/netconfig now (y/n) ?"
read ANSWER
[ "x$ANSWER" = "xy" ] && /sbin/netconfig
exit
fi
 
Old 12-23-2005, 01:25 PM   #6
PDock
Member
 
Registered: Aug 2004
Distribution: Slack10 & curr. tried numerous
Posts: 189

Original Poster
Rep: Reputation: 37
Worth the trip here, thanks alienDog had never seen y/n tested as "x$ANSWER" = "xy" , pretty slick.
ppd
 
Old 12-23-2005, 07:03 PM   #7
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
 
  


Reply



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
Bash Script, no new line for echo command jorisb Linux - General 5 11-05-2005 12:08 AM
Bash Script; command not found twintornado Programming 2 06-01-2005 09:59 AM
Bash script - repeated command satimis Programming 27 10-28-2004 05:02 AM
Simple Bash Script Help Command kemplej Linux - Software 1 03-11-2004 03:52 AM
script 'exit' command kilobravo Linux - General 8 01-16-2003 03:24 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:22 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
Open Source Consulting | Domain Registration