LinuxQuestions.org
Visit Jeremy's Blog.
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 10-02-2005, 12:06 AM   #1
TigerLinux
Senior Member
 
Registered: Sep 2005
Location: Kuala Lumpur, Malaysia
Distribution: Ubuntu 11.04
Posts: 1,731

Rep: Reputation: 30
How to create batch file?


my netscape 7.2 is in /usr/local/netscape
everytime i have to go to that folder and type
./netscape
to launch it.
in DOS, i can create a file named
netscape.bat,
inside typed
cd /usr/local/netscape
./netscape


in linux, how to do it?
 
Old 10-02-2005, 12:58 AM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
You don't really need a batch file (or a script in Linuxese) to do this. I'll show you two different ways.

1. Create an alias
At the command line type this:
Code:
alias netscape="cd /usr/local/netscape; ./netscape"
From that point on, you can type "netscape" at the prompt, and it will change directory and launch netscape for you. If you want to make it permanent, edit ~/.bashrc and add the line above at the end of the file. The next time you log into the system, the alias will be set up automatically.


2. Modify your PATH environment variable.
At a command line type this:
Code:
export PATH=$PATH:/usr/local/netscape
Then you can launch netscape from anywhere. The system will check /usr/local/netscape for executable files just like /bin, /usr/bin, etc. You won't even need to change directories anymore. Just type "netscape" and it'll work. Similar to the alias before, you need to modify a file to make the change permanent. Edit ~/.bash_profie, and put the export line above at the end of the file. The next time you log in, it should work.


NOTE: with both of these methods, you'll need to completely log out if you make the change permanent. Opening a new xterm won't work. If you want to be absolutely sure, reboot the machine.

Last edited by Dark_Helmet; 10-02-2005 at 04:03 AM.
 
Old 10-02-2005, 01:27 AM   #3
TigerLinux
Senior Member
 
Registered: Sep 2005
Location: Kuala Lumpur, Malaysia
Distribution: Ubuntu 11.04
Posts: 1,731

Original Poster
Rep: Reputation: 30
what is this :
edit ~/.bashrc

~ mean what? the folder name?
 
Old 10-02-2005, 01:27 AM   #4
TigerLinux
Senior Member
 
Registered: Sep 2005
Location: Kuala Lumpur, Malaysia
Distribution: Ubuntu 11.04
Posts: 1,731

Original Poster
Rep: Reputation: 30
export PATH=$PATH:/usr/local/netscape"

$PATH is it the name of my folder?
 
Old 10-02-2005, 01:39 AM   #5
IBall
Senior Member
 
Registered: Nov 2003
Location: Perth, Western Australia
Distribution: Ubuntu, Debian, Various using VMWare
Posts: 2,088

Rep: Reputation: 62
~ is a "shortcut" that means your home directory (Probably /home/tigerlinux)

~/.bashrc is a file in your home directory where you change the settings for the shell.

$PATH is an environment variable that contains the list of directories where Linux will search for programs to execute. If you enter the command "echo $PATH", you will get an output like this "/bin:/usr/bin:/usr/X11R6/bin". This means that if you type a command, say "netscape", Linux will search /bin, then /usr/bin, the /usr/X11R6/bin for it.

The command "export PATH=$PATH:/usr/local/netscape" will add /usr/local/netscape to the end of this list.

There is another way to add netscape to your path - make a symbolic link to it in /usr/bin. This way, all users on your machine can "see" it. As root:
Code:
ln -s /usr/local/netscape/netscape /usr/bin
I hope this helps
--Ian
 
Old 10-02-2005, 01:42 AM   #6
TigerLinux
Senior Member
 
Registered: Sep 2005
Location: Kuala Lumpur, Malaysia
Distribution: Ubuntu 11.04
Posts: 1,731

Original Poster
Rep: Reputation: 30
thanks
 
Old 10-02-2005, 03:44 AM   #7
TigerLinux
Senior Member
 
Registered: Sep 2005
Location: Kuala Lumpur, Malaysia
Distribution: Ubuntu 11.04
Posts: 1,731

Original Poster
Rep: Reputation: 30
this is the most useful
export PATH=$PATH:/usr/local/netscape
 
Old 10-02-2005, 06:38 AM   #8
IBall
Senior Member
 
Registered: Nov 2003
Location: Perth, Western Australia
Distribution: Ubuntu, Debian, Various using VMWare
Posts: 2,088

Rep: Reputation: 62
Quote:
Originally posted by TigerLinux
this is the most useful
export PATH=$PATH:/usr/local/netscape
It depends on how many programs you install like this - if you install many of them, your PATH will
become unmanagebly long. It would be useful if there were several programs in the same directory,
but when there is only one a symbolic link is better.

As far as I know, the "normal" way is the symbolic link, like I mentioned above, but who needs to be normal
All the different ways of achieving the same thing all have their pros and cons in different situations.

--Ian
 
Old 10-18-2005, 03:49 AM   #9
AnRkey
Member
 
Registered: Dec 2004
Location: UK
Distribution: Ubuntu, Fedora and not for long, M$ SuSE
Posts: 59

Rep: Reputation: 15
I want to mount multiple images and unmount them when my cp command has completed its task.

so...

mount whatever here
cp that to here
umount whatever
mount somethingelse here
cp this to here
umount somethingelse

get the idea...? sorry for the crap example

Also how do i run it.

I tried making a .sh file and running it as follows ./example.sh and no chance of it working
 
Old 10-18-2005, 04:01 AM   #10
phil.d.g
Senior Member
 
Registered: Oct 2004
Posts: 1,192

Rep: Reputation: 101Reputation: 101
Make a new text file and the first line should be
Code:
#!/bin/bash
then enter all your commands, one command per line then save and exit. Now you need to give that file execute permission so do
Code:
chmod 744 example
then you can run it
Code:
/path/to/example/srcipt/example
If you want to learn more about scripting you could add error checking to the script to make it more robust
 
Old 10-18-2005, 04:04 AM   #11
AnRkey
Member
 
Registered: Dec 2004
Location: UK
Distribution: Ubuntu, Fedora and not for long, M$ SuSE
Posts: 59

Rep: Reputation: 15
Talking

I would have your children if I was a woman! :P
 
Old 03-06-2007, 05:52 AM   #12
TigerLinux
Senior Member
 
Registered: Sep 2005
Location: Kuala Lumpur, Malaysia
Distribution: Ubuntu 11.04
Posts: 1,731

Original Poster
Rep: Reputation: 30
thanks, i need the info i asked before.
 
Old 09-26-2011, 08:50 AM   #13
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,464

Rep: Reputation: Disabled
Another approach would be to move the executable (netscape in this case) from /usr/local to /usr/local/bin. This would be the normal resting place for a system specific executable file. /usr/local/bin is normally found in the PATH variable by default. On my system no individual files are found in /usr/local; only directories are there.
ciao,
jdk
 
Old 09-26-2011, 10:47 AM   #14
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
jdkaye, this thread is several years old. It was only shown because another post was made to it today (and has since been split into a new thread).
 
Old 09-26-2011, 11:10 AM   #15
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,464

Rep: Reputation: Disabled
Thanks for the heads-up Nylex. I hadn't noticed the date.
ciao,
jdk
 
  


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
Sftp using a batch file JeRrYmAn Linux - Security 2 05-05-2006 11:15 AM
How to create a batch file? Franziss Programming 8 05-16-2005 01:36 AM
batch file for chmod's? teodavinci Linux - Networking 1 08-13-2004 03:39 PM
writing a batch file ???? Micro Linux - General 3 01-09-2003 12:04 PM
Bigslack Batch File Mal Slackware 1 07-03-2002 11:32 PM


All times are GMT -5. The time now is 07:11 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