nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

Shell script to delete a file with a dialog utility

This is a discussion on Shell script to delete a file with a dialog utility within the Shell scripting forums, part of the Development/Scripting category; Hello, I am learning shell script by following online documentation of vivek (freeos.com). I need some help to fix the ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 02-20-2007, 02:21 PM
Junior Member
User
 
Join Date: Dec 2006
Location: Hyderabad,India.
Posts: 16
Rep Power: 0
shankar100
Send a message via Yahoo to shankar100
Default Shell script to delete a file with a dialog utility

Hello,

I am learning shell script by following online documentation of vivek (freeos.com). I need some help to fix the problem. please see the below script.

dialog --title "Input- Delete a file" --backtitle "Welcome to linux dialog utility" --inputbox "Enter the file name to delete" 8 60 2>/home/shankar/name
sel=$?
out=`cat /home/shankar/name`
case $sel in
0) rm $out; echo "file is deleted";;
1) echo "You pressed cancel";;
255) echo "You pressed ESC";;
esac
rm /home/shankar/name

The above script will delete the given file, what if there is no file exists ( if (! -f $out) ). The script should check for the file on the system , if finds delete that otherwise it leave a message "no such file exists". Please help me
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-21-2007, 09:17 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Any distro with shell
Posts: 906
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Hello shankar,

Here is the script

Code:
#!/bin/bash
TMPFILE="/tmp/filename.txt"
dialog --title "Input - Delete a file" --backtitle "Welcome to Linux delete" --inputbox "Enter delete file name" 8 60 2>$TMPFILE
sel=$?
out=$(cat $TMPFILE)
if [ ! -f $out ]; then
  echo "Fie $out does not exists"
  exit 1
else
  case $sel in
   0) /bin/rm $out; echo "File $out has been deleted";;
   1) echo "You pressed cancel";;
   255) echo "You pressed ESC";;
  esac
fi
/bin/rm $TMPFILE
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
  #3 (permalink)  
Old 02-21-2007, 11:32 AM
Junior Member
User
 
Join Date: Dec 2006
Location: Hyderabad,India.
Posts: 16
Rep Power: 0
shankar100
Send a message via Yahoo to shankar100
Default

Quote:
Originally Posted by nixcraft
Hello shankar,

Here is the script

Code:
#!/bin/bash
TMPFILE="/tmp/filename.txt"
dialog --title "Input - Delete a file" --backtitle "Welcome to Linux delete" --inputbox "Enter delete file name" 8 60 2>$TMPFILE
sel=$?
out=$(cat $TMPFILE)
if [ ! -f $out ]; then
  echo "Fie $out does not exists"
  exit 1
else
  case $sel in
   0) /bin/rm $out; echo "File $out has been deleted";;
   1) echo "You pressed cancel";;
   255) echo "You pressed ESC";;
  esac
fi
/bin/rm $TMPFILE
Thank you, works fine
Reply With Quote
  #4 (permalink)  
Old 03-02-2007, 06:08 AM
Junior Member
 
Join Date: Mar 2007
Posts: 1
Rep Power: 0
borsel
Default Re: Shell script to delete a file with a dialog utility

Quote:
Originally Posted by shankar100
Hello,

I am learning shell script by following online documentation of vivek (freeos.com). I need some help to fix the problem. please see the below script.

dialog --title "Input- Delete a file" --backtitle "Welcome to linux dialog utility" --inputbox "Enter the file name to delete" 8 60 2>/home/shankar/name
sel=$?
out=`cat /home/shankar/name`
case $sel in
0) rm $out; echo "file is deleted";;
1) echo "You pressed cancel";;
255) echo "You pressed ESC";;
esac
rm /home/shankar/name

The above script will delete the given file, what if there is no file exists ( if (! -f $out) ). The script should check for the file on the system , if finds delete that otherwise it leave a message "no such file exists". Please help me


Hi,

could you please tell me how you got the dialog utility .I am running ubuntu , not redhat.

thanks
Reply With Quote
  #5 (permalink)  
Old 03-02-2007, 10:22 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Any distro with shell
Posts: 906
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default How to install dialog utility under Ubuntu Linux?

It is also installed under Ubuntu by default. If not type the following command:
Code:
sudo apt-get install  dialog
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Shell Delete Directory chimu Slackware 2 05-31-2008 03:36 PM
Shell Script to Automatically Delete a File via Cron Job kakarla Shell scripting 2 01-29-2008 08:54 AM
shell script for ftp the file vishal_titre Shell scripting 3 12-10-2007 08:40 AM
need help to add user password using dialog utility vishal Titre Shell scripting 3 07-13-2006 05:20 PM
error shell script no such file or directory /bin/sh Linux software 1 01-08-2006 08:34 PM


All times are GMT +5.5. The time now is 05:56 AM.


Powered by vBulletin® Version 3.7.2 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36