Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 113
  • Last Modified:

Source shell script

Hi Experts,

1)Is it possible to get the flag status of one script to another.

Suppose.

1.sh
#!/bin/sh
source 2.sh
(If [Flag = True ] )&& (source 3.sh)

Open in new window


2.sh
#!/bin/sh
Some code here
Flag = True

Open in new window


2) Please share some knowledge on Global variables and set command.I was bit confused checking the tutorials .

Thanks
0
magento
Asked:
magento
  • 4
  • 3
  • 2
2 Solutions
 
TintinCommented:
There's a few different ways.

1.   Sourcing a file (like you have), eg:

script1.sh

#!/bin/bash
source /path/to/script2.sh

if [ $flag = true ]
then
      ...
fi

Open in new window


script2.sh

flag=true

Open in new window



or by exporting variables, eg:

script1.sh

#!/bin/bash

export flag=true
/path/to/script2.sh

Open in new window


script2.sh

#!/bin/bash
echo "flag=$flag"

Open in new window


or by passing variables, eg:

script1.sh

#!/bin/bash

/path/to/script2.sh true

Open in new window


script2.sh

#!/bin/bash
flag=$1
echo "flag=$flag"

Open in new window

0
 
magentoAuthor Commented:
Thank you so much Tintin.

If i install ubuntu , can i able to work on terminals like we work in putty ? eg.creating script, test it .
0
 
omarfaridCommented:
one thing about variables to know.

You can pass variables to a script if they are exported.

source will run the script within the current script.

Please run below scripts and see difference

1.sh:

var1=2
var2=3
export var1

2.sh:

echo $var1
echo $var2
var1=1
var3=4

3.sh:

1.sh
2.sh
echo $var1
echo $var2
echo $var3

4.sh:

source 1.sh
source 2.sh
echo $var1
echo $var2
echo $var3
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
omarfaridCommented:
for your other question, yes you can run terminal either on the console of the system or via putty or X windows and run scripts, etc.
0
 
magentoAuthor Commented:
Omarfarid,

Please tell me how to open the terminal .

Once i logged in i see a horizontal menu available , where i can see the terminal options?

Thanks
0
 
TintinCommented:
Depending on your window manager, you should be able to just start typing 'terminal' to bring up the appropriate icon to click on.
0
 
omarfaridCommented:
It depend on your interface. Please see link below:

https://help.ubuntu.com/community/UsingTheTerminal
0
 
magentoAuthor Commented:
Thanks Tintin and Omarfarid for your help .
0
 
omarfaridCommented:
Welcome
0

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now