LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 02-12-2011, 11:20 PM   #1
bostonantifan
Member
 
Registered: May 2006
Location: Leominster, Massachusetts
Distribution: Kubuntu 10.04
Posts: 56

Rep: Reputation: 15
bash script: how to assign command ouput to a variable without executing it?


I'm trying to execute the following command within a bash script:
Code:
tac /var/log/system.log | head -1
The script I wrote is:
Code:
#!/bin/bash
$test1="$(tac /var/log/system.log | -1)
echo $test1
When I run the script, this is the output I get:
Code:
Sat Feb 12 23:24:27 EST 2011 
/var/log ->peterv@MBP17.local<528>$: but.sh

/Users/peterv/bin/but.sh: line 2: =Feb 12 23:57:54 MBP17 ReportCrash[14447]: Saved crash report for CapsSee[294] version 1.02 (1.01) to /Users/peterv/Library/Logs/DiagnosticReports/CapsSee_2011-02-12-235754_MBP17.crash: No such file or directory


Sat Feb 12 23:24:27 EST
The output in red above is what I'm expecting to be in variable $test1, but it looks as though it's trying to execute that text as a command. I'm assuming that there's some syntax I fouled up, but I can't see it. If anyone can help me out, I'd be very grateful.
 
Old 02-12-2011, 11:55 PM   #2
bostonantifan
Member
 
Registered: May 2006
Location: Leominster, Massachusetts
Distribution: Kubuntu 10.04
Posts: 56

Original Poster
Rep: Reputation: 15
Never mind!

Never mind! The extraneous "$" I mistakenly prepended to the variable assignment caused my problem.
 
  


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 script: executing string command chuckj Programming 8 06-17-2010 07:22 AM
Bash script run via cron not executing MYSQL command mackstar Linux - Server 4 04-23-2009 05:01 AM
bash script: how to assign an output (not the result) to a variable? Singing Banzo Programming 8 10-01-2006 06:29 PM
set the ouput of a command to a variable true_atlantis Linux - Newbie 2 03-23-2006 03:30 PM
Bash script; command and args in variable. magjo813 Programming 2 02-16-2004 09:22 AM

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

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