HI Team,
I have two shell script with me a.sh and b.sh
Content in a.sh
#!/bin/bash
a=20
./b.sh
Content in b.sh
#!/bin/bash
echo “The value of a is $a”
When i run the script the value of a is not printing . Please let us know how to use variable from one shell script to another shell script
luk4z_7
December 24, 2016, 12:53pm
#2
You can use “source” for load the another file
a.sh
#!/usr/bin/env bash
a='testing'
b.sh
#!/usr/bin/env bash
source a.sh
echo $a
Executing
./b.sh
testing
HI ,
Thanks for your reply. It is working fine. But the problem is if i have more than 100 variables in a.sh script we cannot able to do source for all variables. Then in that case how to use a.sh variable to b.sh file
Regards
Arun
luk4z_7
December 26, 2016, 4:19pm
#4
No problem, put all variables in another file shell for include, like this:
colorcodes.sh
#!/bin/sh
# ********************************************* #
# * Color Code Script for Modular Scripting * #
# * Author: Bill M. and Dennis F. * #
# * HDUS Support * #
# * Date: 05-21-2014 * #
# * Version 0.27 * #
# ********************************************* #
############### 8 Bit Color Codes ###############
BOLD="\e[1m";
RESET="\e[0;00m";
BLACK="\e[0;30m";
WHITE="\e[97m";
RED="\e[1;31m";
YELLOW="\e[1;33m";
GREEN="\e[1;32m";
BLUE="\e[34m";
MAGENTA="\e[95m";
CYAN="\e[36m";
GRAY="\e[90m";
DARKGRAY="\e[1;30m";
BAD="\e[41m"; #White Text on Red Background;
############### Short Codes ###############
BD="\e[1m"; #BOLD;
RS="\e[0;00m"; #RESET;
H1="\e[1m\e[34m"; #BOLD and BLUE;
H2="\e[1m\e[97m"; #BOLD and WHITE;
SH1="\e[1m\e[36m"; #BOLD and CYAN;
SH2="\e[1m\e[97m"; #BOLD and WHITE;
CM1="\e[1m\e[95m"; #BOLD and MAGENTA;
CM2="\e[1m\e[97m"; #BOLD and WHITE;
W1="\e[97m"; #WHITE;
R1="\e[31m"; #RED;
R2="\E[1;31m"; #SOFTER RED
Y1="\e[1;33m"; #YELLOW;
G1="\e[1;32m"; #GREEN;
B1="\e[34m"; #BLUE;
C1="\e[36m"; #CYAN;
M1="\e[95m"; #MAGENTA;
G2="\e[90m"; #GRAY;
BL="\e[0;30m"; #BLACK
DG="\e[1;30m"; #DARK GRAY
##### Reset Environment Variables
# 1=""
INPUTZ=""
CHECKACCOUNT=""
THEDOMAIN=""
THEACCOUNT=""
linenum=""
inodes=""
nobody=""
userskip=""
flag=""
flag2=""
grepip=""
digip=""
plan=""
location=""
line=""
month=""
day=""
today=""
host=""
digns=""
axonmarkdown.sh
#!/bin/bash
##Enable Color
. colorcodes.sh
echo $BLUE;
printf "${BLUE}\n1.${RS} ${RED} AXON Logs analysis:${RESET}\n"