James Franco
James Franco

Reputation: 4706

what does a if mean during variable assignment

I am going through a couple of BASH scripts. And I came across something like this

VAR_S=$(dd if=${MY_FILE} bs=16 count=1 skip=1024 iflag=skip_bytes 2>/dev/null | hexdump -e '16/1 "%02x"')

Apparently the Variable VAR_S should not be empty and I am trying to wrap my head around this statement. What does if=${MY_FILE} mean here. I am trying to figure out why VAR_S is returning empty when I echo it.It seems to me like if is a simple variable being assigned the value of MY_FILE. In that case I dont understand the significance of assignment and why not just use dd ${MY_FILE}

Upvotes: 0

Views: 50

Answers (2)

Vaibhav
Vaibhav

Reputation: 5947

Check the Man file for DD.

http://man7.org/linux/man-pages/man1/dd.1.html

You will notice that these are all parameters and not assignments.

Following is something I had used sometime back. Hope it helps.

http://www.computerhope.com/unix/dd.htm

Upvotes: 1

choroba
choroba

Reputation: 241758

See man dd for explanation: if stands for "input file". These aren't variable assignments, but parameters. Variable assignment can't follow a command.

Upvotes: 4

Related Questions