Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

source equivalent in HPUX

SOLVED
Go to Solution
Super Advisor

source equivalent in HPUX

Hi,

I am writing a script that work perfectly well in linux environment as it will run

source file.txt

Is there an HPUX equivalent as I need to include that file to the script?
abc
10 REPLIES
Honored Contributor Honored Contributor

Re: source equivalent in HPUX

> [...] in HPUX

uname -a

> I am writing a script [...]

With my weak psychic powers, I can't see it.
I can't even see its first line (the line
with the "#!").

> [...] linux environment [...]

uname -a

> Is there an HPUX equivalent [...]

No, but there's probably a _shell_
equivalent, if only we knew which shell(s)
you were using. if "source" doesn't work in
your shell, then I'd suggest ".":

. file.txt
Honored Contributor Honored Contributor

Re: source equivalent in HPUX

run it with . before it
Honored Contributor Honored Contributor

Re: source equivalent in HPUX

> run it with . before it

Run what how, with . before what???

What, exactly, did this contribution actually
contribute here? Was your dot easier to read
than my dot? (And I thought that _I_ had too
much time to kill.)
Acclaimed Contributor Acclaimed Contributor

Re: source equivalent in HPUX

Hi:

On Linux and Apple systems, the 'bash' shell is the default shell. As such it has the 'source' as well as the 'dot' command, both of which do the same thing.

HP-UX's default shell is a POSIX shell closer to the Korn shell and found in '/usr/bin/sh' or '/sbin/sh' for 'root'. You can still specify an interpreter ("she-bang") line of simply '/bin/sh' since this is a symlink to '/usr/bin/sh' in HP-UX.

If you want to include a file (very commonly variable declarations and assignments) into another script, you speak of "sourcing" or reading it with the 'dot' command:

#!/bin/sh
...
# include the "mystuff' file here:
. /usr/local/bin/mystuff
echo "now continuing..."
...

Notice the 'dot' followed by whitespace, followed by the file to be included ('sourced' or read, whatever term you prefer).

Regards!

...JRF...
Acclaimed Contributor Acclaimed Contributor

Re: source equivalent in HPUX

As mentioned, "source" is used by the scummy C shell and its descendants. A real shell uses "." to source files.
Acclaimed Contributor Acclaimed Contributor

Re: source equivalent in HPUX

HI (again):

> As mentioned, "source" is used by the scummy C shell and its descendants. A real shell uses "." to source files.

While I wholly agree, when it comes to the "scummy C shell and its descendants", I'd certainly consider the Bash shell to be a "real shell" that can use *either* the 'source' command or the 'dot' command to achieve the same result.

Regards!

...JRF...
Super Advisor

Re: source equivalent in HPUX

hi,

I have tried the . dot to source file but it doesn't seem to work in my HPUX but work fine in Linux.

config.txt
HOST=myserver

script
#!/bin/sh
. config.txt
echo $HOST

I get the the config.txt not found error. Any idea why
abc
Acclaimed Contributor Acclaimed Contributor

Re: source equivalent in HPUX

>I have tried the . to source file but it doesn't seem to work in my HP-UX
>. config.txt
>I get the the config.txt not found error.

Why aren't you using an absolute path to config.txt?
Either it must be in $PATH or it must absolute or relative.
Super Advisor

Re: source equivalent in HPUX

The reason for that I will consider pass the config.txt to the script as argument.

for example, script.sh config.txt
it make the maintenance easier as I only need one script but many config.txt to cater for different server
abc
Highlighted
Acclaimed Contributor Acclaimed Contributor

Re: source equivalent in HPUX

>I will pass the config.txt to the script as argument.

Then you have to pass in ./config.txt or $PWD/config.txt.

Or you have to add "." to PATH inside your script.