≡ Menu

Linux / Unix: Bash Shell Assign Printf Result To Variable

How do I assign printf command result to a shell variable under Unix like operating systems?

The printf command syntax is as follows:

printf "FORMAT" var
var=$(printf "FORMAT" var1)
var="$(printf "FORMAT" var1)"


Type the following command:

printf "%s\n" $dir

To store result to a variable called j, enter:

j=$(printf "%s" $dir)
echo "$j"
printf "%s\n" $j

{ 0 comments… add one }

Leave a Comment

   Tagged with: , , , ,