LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-17-2009, 07:43 PM   #1
babypeng
Member
 
Registered: Nov 2007
Distribution: Puppy
Posts: 42

Rep: Reputation: 15
.bat equivalent feature for Linux


Hello All,

When I want to run a batch file on Windows XP
I create a text file with the batch commands written in it in text,
and save it (on the desktop).
I then change the name from *.txt to *.bat .
I double click on it to run it.

How do I achieve the same feature on Debian Gnome/KDE ?
I want to have an icon on the desktop, on which I double click.

To be more precise, I would like it to turn the computer off
(I guess it's done with the command "halt" ).


Any help appreciated,

Babypeng
 
Old 04-17-2009, 07:56 PM   #2
Robhogg
Member
 
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 88
If it won't let you just do this (and on my system, if I double-click a shell-script, it asks me if I want to run it):

In Gnome, right-click on the desktop, select "create laucher", give it a name and enter the command (path to the script you want to run, along with any command-line arguments). You can choose an icon for it as well. Not used KDE for a while, but I'm pretty sure it is very similar there.

A few things:
  • The file must be set to be executable (from the command line: chmod +x filename, or can be done through the permissions tab in the right-click file properties dialogue)
  • The command-line shutdown / halt commands normally requires root privileges, so to run it as a normal user, without a password, you'd have to configure it in sudoers)
  • You should just be able to add a shutdown button to the panel ("taskbar") quite easily - right-click on it, select "Add to panel..." and choose the appropriate applet

Last edited by Robhogg; 04-17-2009 at 08:01 PM.
 
Old 04-17-2009, 08:54 PM   #3
maresmasb
Member
 
Registered: Apr 2009
Posts: 108

Rep: Reputation: 24
Shell scripts are the equivalent to the MS world's batch scripts. A very simple BASH shell script would be:
Quote:
#!/bin/sh
echo "this" > /home/myname/output.txt
Make the script executable (chmod a+x) to allow launching from the Desktop by double-clicking.

Under Gnome launching a shell script will bring up a confirmation dialog - Gnome is known to distrust the intelligence of users, but in the end it's good security.

When using Konqueror under KDE the double clicking executes the script immediately. You can use Konqueror also under Gnome. I prefer KDE stuff for applications, but use Gnome as my main desktop - you don't get much weirder than that in times of Gnome-KDE flame wars. I assume that other window managers have their own ways of dealing with double-clicked shell scripts.

You also have the choice of using kdialog to combine scripting with generating GUI dialogs. Quite handy!

It's a good practice to use full pathnames in scripts, to allow them to be run as cron jobs or to be launched by double-clicking also for other users.

Last edited by Tinkster; 10-30-2010 at 04:21 PM.
 
Old 04-17-2009, 10:19 PM   #4
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,186

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
And, for your specific task, check out the "widgets." (Right click on the task bar at the top of the screen if you're using GNOME.There's usually one there to halt the system.
 
Old 04-17-2009, 10:33 PM   #5
ssaha
Member
 
Registered: Feb 2009
Location: Kolkata,India
Distribution: Fedora 8,Ubuntu 8.04, 8.10, 9.04, 9.10
Posts: 108

Rep: Reputation: 18
simply save the file with .sh extension instead of .bat.
now go to the terminal and type chmod u+x filename to change permissions.
now just type the filename and hit enter to execute it.
 
Old 04-17-2009, 11:32 PM   #6
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 16,818

Rep: Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408
it can be done with a *.sh script BUT the desktop is a "special" type of folder
-- for Gnome --
just r-click on the screen and select " create launcher "
and fill in the boxes
for example i use this to reboot ( i have 3 OS on the box)
http://bayimg.com/cApHDAAbb
-- or --
Code:
[Desktop Entry]
Version=1.0
Encoding=UTF-8
Name=Reboot
Type=Application
Terminal=false
Icon[en_US]=reboot
Name[en_US]=Reboot
Exec=reboot
Icon=reboot
GenericName[en_US]=
and save as reboot.desktop
 
  


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
Linux equivalent of bat files anjanesh Linux - Newbie 19 12-30-2005 01:15 PM
What is the autoexec.bat and config.sys equivalent of linux lemuel Linux - Newbie 4 12-07-2004 10:34 PM
Linux Startup - AutoExec.bat equivalent? perry Linux - Software 6 05-04-2004 12:13 AM
.bat file equivalent in linux? Gnute Linux - General 5 08-17-2003 10:21 AM
Autoexec.bat Equivalent dwpondscum Linux - Distributions 5 06-16-2003 10:51 AM


All times are GMT -5. The time now is 08:59 AM.

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