source equivalent in HPUX (493 Views)
Reply
Super Advisor
kholikt
Posts: 545
Registered: ‎02-12-2001
Message 1 of 11 (493 Views)
Accepted Solution

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
Please use plain text.
Honored Contributor
Steven Schweda
Posts: 9,036
Registered: ‎02-23-2005
Message 2 of 11 (493 Views)

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
Please use plain text.
Honored Contributor
Emil Velez
Posts: 1,450
Registered: ‎05-17-2000
Message 3 of 11 (493 Views)

Re: source equivalent in HPUX

run it with . before it
Please use plain text.
Honored Contributor
Steven Schweda
Posts: 9,036
Registered: ‎02-23-2005
Message 4 of 11 (493 Views)

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.)
Please use plain text.
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 5 of 11 (493 Views)

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...
Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,381
Registered: ‎03-06-2006
Message 6 of 11 (493 Views)

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.
Please use plain text.
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 7 of 11 (493 Views)

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...
Please use plain text.
Super Advisor
kholikt
Posts: 545
Registered: ‎02-12-2001
Message 8 of 11 (493 Views)

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
Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,381
Registered: ‎03-06-2006
Message 9 of 11 (493 Views)

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.
Please use plain text.
Super Advisor
kholikt
Posts: 545
Registered: ‎02-12-2001
Message 10 of 11 (493 Views)

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
Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,381
Registered: ‎03-06-2006
Message 11 of 11 (493 Views)

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.
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation