LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 03-27-2016, 06:39 AM   #1
dinakumar12
Member
 
Registered: Mar 2010
Location: INDIA (chennai)
Distribution: centos
Posts: 271
Blog Entries: 7

Rep: Reputation: 18
Comapring variables using diff inside bash script


Hi,

I was searching to compare variables using diff command.

diff <(echo "$a") <(echo "$b")

when i use in bash shell it works.

But when i use the same command inside script it didnt. What i am missing here. Can any one Please suggest.

Thanks,
Dinesh.
 
Old 03-27-2016, 09:15 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,359
Blog Entries: 3

Rep: Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767
What is the first line of your shell script? Is it

Code:
#!/bin/sh
or is it

Code:
#!/bin/bash
or is it

Code:
#!/bin/zsh
If it is the former, then the process substitution <( ) will not work. Process substitution only works in a few shells, bash and zsh are the two that I know of.
 
Old 03-28-2016, 01:18 AM   #3
dinakumar12
Member
 
Registered: Mar 2010
Location: INDIA (chennai)
Distribution: centos
Posts: 271

Original Poster
Blog Entries: 7

Rep: Reputation: 18
Hi Turbocapitalist,

its #!/bin/sh and thats the reason it didn't work. Changed the shebang value to #!/bin/bash worked.

Thanks a lot for your tips. Is there any option to run the same sh shell environment.


Thanks,
Dinesh.
 
Old 03-28-2016, 01:27 AM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,359
Blog Entries: 3

Rep: Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767
You can run sh as your shell if you like. It'll be missing a lot of niceties though. Just run it from your regular shell:

Code:
/bin/sh
And then type 'exit' to get back to your regular shell when you are done. If you want the change to be permanent, use 'usermod' or the graphical equivalent.
 
Old 03-30-2016, 09:09 PM   #5
dinakumar12
Member
 
Registered: Mar 2010
Location: INDIA (chennai)
Distribution: centos
Posts: 271

Original Poster
Blog Entries: 7

Rep: Reputation: 18
I tried executing the script by sh scriptname to run in sh environement and yes its very linitted i guess. diff not working over there for comaring variables.

But its works fine with bash and thats what i ecpected.

Thanks for your response. Marking the thread as solved now.

Thanks,
Dinesh.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash diff between variables ? patrick295767 Programming 3 08-24-2011 08:09 AM
variables inside a shell script dsids Programming 12 01-04-2011 03:47 PM
Bash Script: parse active process stderr, strip, dump into variables, use variables TimeFade Programming 1 02-13-2010 06:09 AM
bash: variables inside while loop J_Szucs Programming 5 07-19-2009 08:24 AM
how to stop parsing shell variables in bash script inside cat area? jackandking Linux - Newbie 2 03-10-2009 06:44 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 12:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration