In Shell scripting (Linux/Ubuntu , Bash) , why do we use echo and bc commands together ? I am new to Shell scripting and have a basic understanding of pipes .
I know that bc is kind of a seperate language . How does the following statement actually work (Just an example) ?
echo 5+6 | bc
In Shell scripting (Linux/Ubuntu , Bash) , why do we use echo and bc
Share
You can use that program combination for another set of powerful operations, for example you can convert from hexadecimal to binary like this
It will print:
101000010101As for the process of echoing and using the
|operator, it just make the output of theechocommand an input for thebcprogram, you can achieve the same using for example:bc <<< "5 + 2"bcdoes not read operations from command line arguments, instead it reads it from an input file or in an interactive sessionAnother example of this useful combination is the calculation of really big quantities, like:
A note about the
<<<: it passes a string on a single line as an input file to the command, if the program reads its input from a file, with<<<you can convert a string to a “file” and then pass this “file” to the program.