I've been trying to save in a variable the value of the convert of a number from decimal to binary, like this:

echo "obase=2;$num1" | bc   | tee -a register.txt

but I don't want to show it in screen, because the idea is just do the convert and save it in the file like register.txt

How can I do so?

  • Add a >/dev/null at the end. num1=10; echo "obase=2;$num1" | bc | tee -a register.txt >/dev/null – Valentin Bajrami Oct 22 '14 at 5:38
  • possible duplicate of Can a bash script be hooked to a file? – PersianGulf Oct 22 '14 at 5:58
  • Your original question had num = 10`, you should leave out the spaces. Also don't ask if someone can help, that can be answered by "yes"/"or" and doesn't solve your real problem. – Anthon Oct 22 '14 at 6:01

The tee command is there to split the output, most often used to get text to a file and to the screen.

Just leave it out and use output redirection (appending) to file with >>:

echo "obase=2;$num1" | bc >> register.txt

Instead of using tee, just use I/O-Redirection of the shell:

echo "obase=2;$num1" | bc >>register.txt

The >>-statement causes the output to be redirected (> redirect, >> append) to the file. The -a flag of tee causes also an append to the file. You only need tee if you want the output to be shown in the shell AND redirected to a file.


You can do it using the output redirection as below.

$ bc -l <<<"obase=2;$num" > register.txt

The above command will overwrite any older results. In case if you want to append your results.

$ bc -l <<<"obase=2;$num" >> register.txt

>> - Redirects output (STDOUT) messages in append mode.

> - Redirects output (STDOUT) messages in overwrite mode.

<<< - Here Strings, The word is expanded and supplied to the command on its standard input.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.