LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Creating bash file that changes decimal to binary using obase (https://www.linuxquestions.org/questions/linux-newbie-8/creating-bash-file-that-changes-decimal-to-binary-using-obase-876256/)

hayloiuy 04-21-2011 12:19 AM

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?

David the H. 04-21-2011 12:47 AM

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

nsit_poison 04-21-2011 01:05 AM

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


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