LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-27-2008, 07:17 AM   #1
B-Boy
Member
 
Registered: Jan 2008
Posts: 103

Rep: Reputation: 15
Bash Scripting


Hi everyone

I am a newbie to Linux and scripting anyway I want to write a script that will put the contents on a file1 into a variable1 and the contents of file2 into a variable2 then if they are the same a command must run eg xeyes else they do not match...something like that


here is my script please dont laugh ;-)
Code:
 #!/bin/bash
LOG= cat /path/file1
LOG1= cat /path/file2
            if [ "$LOG" = "$LOG2" ]; then
                xeyes
            else
                 echo they do not match
            fi
 
Old 05-27-2008, 07:39 AM   #2
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
You need to use either backticks (` - not an apostrophe: ') or the $() construct to evaluate the cat /path/file? commands:
Code:
LOG=$(cat /path/file1)
LOG1=$(cat /path/file2)
I prefer $() as it's more readable and you can nest them more easily.

I addition, to get the contents of a file into a variable, there's no need to use an external program (cat). You can simply use standard input:
Code:
LOG=$(< /path/file1)
The rest of the code should work ok.
 
Old 05-28-2008, 01:15 AM   #3
B-Boy
Member
 
Registered: Jan 2008
Posts: 103

Original Poster
Rep: Reputation: 15
Smile

Quote:
Originally Posted by pwc101 View Post
You need to use either backticks (` - not an apostrophe: ') or the $() construct to evaluate the cat /path/file? commands:
Code:
LOG=$(cat /path/file1)
LOG1=$(cat /path/file2)
I prefer $() as it's more readable and you can nest them more easily.

I addition, to get the contents of a file into a variable, there's no need to use an external program (cat). You can simply use standard input:
Code:
LOG=$(< /path/file1)
The rest of the code should work ok.
thinks for your help it worked
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 scripting stu_mueller Slackware 4 04-15-2008 02:09 PM
bash scripting csdhiman Linux - Server 3 10-12-2007 12:15 AM
Bash scripting help arturhawkwing Linux - General 1 08-10-2006 11:54 AM
help with bash scripting spuzzzzzzz Programming 2 09-02-2004 11:42 PM
Bash scripting SWAT Linux - Newbie 2 11-11-2003 03:21 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:08 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