9

i have many script shell and i want to include a file containing variables in this shell

script?

My var script:

###################################################################################
ORACLE_LOGIN=login
ORACLE_PWD=pwd
CHEMIN_1="/home/"
CHEMIN_2="/scripts/"
LOG_FILE="$CHEMIN_1/max.log"
export ORACLE_SID=oracle_sid
###################################################################################

My script sh:

#!/bin/ksh
#set -x

# ==============   LOAD VAR HERE  ====================================
????

##################################################################
####                          Begin                           ####
##################################################################

write "Begin $0"  

$ORACLE_HOME/bin/sqlplus -s $ORACLE_LOGIN/$ORACLE_PWD@$ORACLE_SID <<EOF >> $LOG_FILE 2>&1 
@$CHEMIN_2/sp_rep_alim_dia_date_max.sql
exit
EOF

write "End."

Thx.

4 Answers 4

16

It depends which shell, but one of these two usually works:

. var

or

source var

I'm not sure about ksh, but I'd imagine both would work.

Sign up to request clarification or add additional context in comments.

2 Comments

sh: line 5: fct_commun.sh: No such file or directory of this type
Does a file named "var" exist in the current directory?
5
. ./name_of_the_var_script

That’s dot + space + dot + slash + filename (because the “dot” utility needs an absolute or relative path to your var script).

2 Comments

sh: line 5: fct_commun.sh: No such file or directory of this type
You do need to specify the correct path ("$(dirname "$0")" as below usually works).
2

use the . (dot) command to source the file

. var_script

A note:

  • if the filename does not contain a slash then bash will attempt to find it in the $PATH.
  • if not found in the PATH, the current directory will be used (unless bash is in POSIX mode).

Ref [the . command][source] in the manual.

So, if you know where it is, use a relative/absolute path for it. [source]: https://www.gnu.org/software/bash/manual/bash.html#index-_002e

2 Comments

sh: line 5: fct_commun.sh: No such file or directory of this type
If that file is in the same directory as the "main" script, then . "$(dirname "$0")"/fct_commun.sh
0

source var worked for me. this link Pass all variables from one shellscript to another? has good explanation for this problem

// Hope this helps..

1 Comment

Welcome to stack Overflow.. If this is an answer then provide useful information regarding this link as well.. Because comment in answer section is not allowed..

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.