Register
It is currently Tue Oct 21, 2014 5:57 am

simple If then script =D


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Wed May 06, 2009 5:05 pm   

Joined: Wed May 06, 2009 4:59 pm
Posts: 1
hey all.

Basically I can't figure this out.

I need a script that will automatically execute a command if i just hit enter when prompted but if i type anything else in it should execute the entered command instead.

So For Example:

if i input nothing it runs nano
if i input vim it runs vim


any ideas?


Calvin


Top
 Profile  
 PostPosted: Thu May 07, 2009 2:47 am   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
Hi

Code:
#!/bin/bash
default_app="vim"

read -p "Which command? [$default_app] " run_app
if [ -z $run_app ]; then
   $default_app
else
   $run_app
fi


Something like this should work :)

Best regards
Fredrik Eriksson


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP