A typical error in bash programming

$a=df|grep vda1|awk '{print $5}'

Above is a typical error in Bash programming for bash newbies, especially for savvy programmers familiar with other languages but bash.

There are two errors in it.

The first is the programmer takes it for granted that the pipeline “df|grep vda1|awk ‘{print $5}'” will be executed and the result is saved in variable a. This is not a correct assumption. Bash will not execute the commands after =, automatically. If you want the command(pipeline) to be executed, you should enclose it with “. So, you should write: `df|grep vda1|awk ‘{print $5}’`.

The second error is you should not use the symbol $ before a variable name in variable assignment. Using the variable name is enough. The dollar symbol is used in situation where you want to expand the variable name to its content.

So, the correct syntax of the above statement is:

a=`df|grep vda1|awk '{print $5}'`
Did you like this?
Tip admin with Cryptocurrency

Donate Bitcoin to admin

Scan to Donate Bitcoin to admin
Scan the QR code or copy the address below into your wallet to send some bitcoin:

Donate Bitcoin Cash to admin

Scan to Donate Bitcoin Cash to admin
Scan the QR code or copy the address below into your wallet to send bitcoin:

Donate Ethereum to admin

Scan to Donate Ethereum to admin
Scan the QR code or copy the address below into your wallet to send some Ether:

Donate Litecoin to admin

Scan to Donate Litecoin to admin
Scan the QR code or copy the address below into your wallet to send some Litecoin:

Donate Monero to admin

Scan to Donate Monero to admin
Scan the QR code or copy the address below into your wallet to send some Monero:

Donate ZCash to admin

Scan to Donate ZCash to admin
Scan the QR code or copy the address below into your wallet to send some ZCash:

Leave a Reply