LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to create batch file? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-create-batch-file-368903/)

TigerLinux 10-01-2005 11:06 PM

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?

Dark_Helmet 10-01-2005 11:58 PM

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.

TigerLinux 10-02-2005 12:27 AM

what is this :
edit ~/.bashrc

~ mean what? the folder name?

TigerLinux 10-02-2005 12:27 AM

export PATH=$PATH:/usr/local/netscape"

$PATH is it the name of my folder?

IBall 10-02-2005 12:39 AM

~ 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

TigerLinux 10-02-2005 12:42 AM

thanks

TigerLinux 10-02-2005 02:44 AM

this is the most useful
export PATH=$PATH:/usr/local/netscape

IBall 10-02-2005 05:38 AM

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

AnRkey 10-18-2005 02:49 AM

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 :(

phil.d.g 10-18-2005 03:01 AM

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

AnRkey 10-18-2005 03:04 AM

I would have your children if I was a woman! :P

TigerLinux 03-06-2007 04:52 AM

thanks, i need the info i asked before.

jdkaye 09-26-2011 07:50 AM

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

Nylex 09-26-2011 09:47 AM

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).

jdkaye 09-26-2011 10:10 AM

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


All times are GMT -5. The time now is 02:10 AM.