Solved

Source shell script

Posted on 2015-01-08
9
105 Views
Last Modified: 2015-01-19
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
Comment
Question by:magento
  • 4
  • 3
  • 2
9 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 250 total points
ID: 40539551
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
 
LVL 5

Author Comment

by:magento
ID: 40540540
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
 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 250 total points
ID: 40541032
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
 
LVL 40

Expert Comment

by:omarfarid
ID: 40541039
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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 5

Author Comment

by:magento
ID: 40543095
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
 
LVL 48

Expert Comment

by:Tintin
ID: 40543462
Depending on your window manager, you should be able to just start typing 'terminal' to bring up the appropriate icon to click on.
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 40543618
It depend on your interface. Please see link below:

https://help.ubuntu.com/community/UsingTheTerminal
0
 
LVL 5

Author Closing Comment

by:magento
ID: 40557166
Thanks Tintin and Omarfarid for your help .
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 40557214
Welcome
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Which Linux flavors will this run on? 6 76
nagios remote hosts 9 43
issue in getting eth0 IP in oracale virtual box Linux VM 4 42
wipe a usb using python 5 25
Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now