I want to assign one or multiple variables at the beginning of a command line in my shell to reuse it in the command invocation. I'm confused of how my shell behaves and want to understand what is happening.
I'm using ZSH but am also interested what the "standard" posix behavior is.
1: % V=/ echo $V # echo is a shell built-in?!?
expected: /. actual: ""
2: % V=/ ls $V # ls is a command
expected: ls /. actual: ls
3: % V=/ ; echo $V
expected: "". actual: /
Here I thought that the semicolon would be equivalent to a new shell line and that I'd need export
.
4: % V=/ ; ls $V
expected: ls. actual: ls /
I'm mostly surprised by lines 1 and 2. Is there any ZSH settings that could cause this or do I just start to use a semicolon to use variables in this way?