Operating System - HP-UX
1835081 Members
2611 Online
110073 Solutions
New Discussion

how to set environment available in script!

 
leyearn
Regular Advisor

how to set environment available in script!

in order to make my script run successfully
i set the PATH environment available in my script

the following:

PATH=/usr/sbin:/usr/bin:/opt/ansic/bin:/usr/ccs/bin:/usr/contrib/bin:/opt/nettla
dm/bin:/opt/graphics/common/bin:/usr/bin/X11:/usr/contrib/bin/X11:/opt/upgrade/b
in:/opt/langtools/bin:/opt/perf/bin:/opt/imake/bin:/opt/hpxt/enware/bin:/opt/hpn
p//bin:/opt/hparray/bin:/sbin:/home/root

one line can't hold all the items
when i execute my script(shellx.txt)# ./shellx.txt
the following error message is produced:


./shellx.txt[3]: dm/bin:/opt/graphics/common/bin:/usr/bin/X11:/usr/contrib/bin/X
11:/opt/upgrade/b: not found.
./shellx.txt[4]: in:/opt/langtools/bin:/opt/perf/bin:/opt/imake/bin:/opt/hpxt/en
ware/bin:/opt/hpn: not found.
./shellx.txt[5]: p//bin:/opt/hparray/bin:/sbin:/home/root: not found.

how can set the available correctly?

6 REPLIES 6
Mark Grant
Honored Contributor

Re: how to set environment available in script!

Leyearn,That PATH is not too long. It would be nice to see your script but I suspect that you have newlines at the end of each line where you set the PATH so"dm/bin:/opt/graphics/common/bin:/usr/bin/X11:/usr/contrib/bin/X11:/opt/upgrade/b" looks like a command.Make sure your PATH doesn't have newlines in it or put "\" at the end of each line.Regards
Never preceed any demonstration with anything more predictive than "watch this"
twang
Honored Contributor

Re: how to set environment available in script!

In my environment, I prepared a environment source file for running script, and source that file in the beginning of each script, see following:
#!/bin/sh
#Env Setting---------
# source the following file to export
# all required env variables, such
# as PATH, ORACLE_SID, ORACLE_HOME...
. /home/oracle/.scriptenv
...
Zigor Buruaga
Esteemed Contributor

Re: how to set environment available in script!

Hi,

When editing your script with "vi", in command mode use ":set list" to view where are the new-lines ( will be "marked" with a dollar symbol ).

As mentioned, looks like you have undesirable new lines in your PATH line.
Kind regards,
Zigor
F. X. de Montgolfier
Valued Contributor

Re: how to set environment available in script!

Hi,

as Mark said, your problem is probably that you did a copy-paste from another source and included erronous newlines in your script.

However, if you still want to add pathes to an existing PATH variable, all you have to do is:

PATH=$PATH;[your new pathes]

Cheers,

FiX

Fragon
Trusted Contributor

Re: how to set environment available in script!

Hi leyearn,
You can use:
export PATH=$PATH:/dir1:/dir2:/dir3
export PATH=$PATH:/dir4:/dir4:/dir6
...
to assign more path!
As I know, the maximum length for POSIX shell variable is 128 characters (maybe), so the strings above 128 will be truncated!

-ux
Bhuvaneswari Selvaraj
Valued Contributor

Re: how to set environment available in script!

From the error, it says that error in line 3, where teh dm/bin line starts. just append a \ at the end of the previous line or do the exports in different line
1. PATH=/usr/sbin:... till /usr/contrib/bin
in the nest line
2. PATH=$PATH:/opt/nettladm and so on..

This will solve your problem.