Operating System - HP-UX
1748181 Members
4081 Online
108759 Solutions
New Discussion юеВ

source equivalent in HPUX

 
SOLVED
Go to solution
kholikt
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 10
Steven Schweda
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
Emil Velez
Honored Contributor

Re: source equivalent in HPUX

run it with . before it
Steven Schweda
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.)
James R. Ferguson
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...
Dennis Handly
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.
James R. Ferguson
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...
kholikt
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
Dennis Handly
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.
kholikt
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