Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 02-13-2011, 12:20 AM   #1
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:
tac /var/log/system.log | head -1
The script I wrote is:
$test1="$(tac /var/log/system.log | -1)
echo $test1
When I run the script, this is the output I get:
Sat Feb 12 23:24:27 EST 2011 
/var/log ->peterv@MBP17.local<528>$:

/Users/peterv/bin/ 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-13-2011, 12:55 AM   #2
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.


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

All times are GMT -5. The time now is 10:14 PM.

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