LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-21-2011, 01:19 AM   #1
hayloiuy
LQ Newbie
 
Registered: Apr 2011
Location: Malaysia
Distribution: Ubuntu
Posts: 6

Rep: Reputation: 0
Creating bash file that changes decimal to binary using obase


Code:
#!/bin/bash

echo 'obase=2;10'|bc 

current_version=$1
echo $current_version

echo   'obase=2; $current_version'|bc    > BinVer.txt
What is the problem? The terminal tells me the $ sign is illegal. Help?
 
Old 04-21-2011, 01:47 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Code:
echo 'obase=2; $current_version' | bc
When you put single-quotes around a text string, everything inside them becomes literal. You need to use double-quotes if you want variables to expand.
(double-quotes don't escape $`\, or ! when history expansion is enabled).
Code:
echo "obase=2; $current_version" | bc
Edit: this is bash pitfall #28
http://mywiki.wooledge.org/BashPitfa...d_bye.2BAC8.27

Last edited by David the H.; 04-21-2011 at 01:50 AM.
 
Old 04-21-2011, 02:05 AM   #3
nsit_poison
LQ Newbie
 
Registered: Apr 2011
Distribution: Fedora
Posts: 7

Rep: Reputation: 0
Read this.
http://www.unix.com/shell-programmin...base-help.html
 
  


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
LXer: Perl and Bash Versions Of Binary To Decimal Conversion Script LXer Syndicated Linux News 0 07-16-2008 11:00 AM
Decimal to binary conversion master General 10 12-21-2007 03:03 AM
bash scripting: loop over a file, replacing two decimal numbers frankie_DJ Programming 2 04-30-2007 05:04 PM
Decimal to binary maldini1010 Programming 6 02-01-2005 05:03 PM
c++ binary to decimal conversion.. miguetoo Programming 13 04-24-2003 10:49 PM


All times are GMT -5. The time now is 08:05 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration