β² 100 βΌ Which way do you expand variables? (lemmy.world) submitted 3 years ago by zephyr@lemmy.world [M] to c/linuxmemes@lemmy.world 23 comments fedilink hide all child comments
[β] DoomBot5@lemmy.world 8 points 3 years ago (2 children) First one has the pitfall of a space at the end of the variable still causing it to fail. permalink fedilink source hideshow 4 child comments replies: [β] venusenvy47@lemdro.id 1 point 3 years ago (1 child) Would a space at the end of the variable be ignored in the second one, though? permalink fedilink source parent hideshow 2 child comments replies: [β] DoomBot5@lemmy.world 1 point 2 years ago It would still be considered a single variable because the entire string is quoted. The first scenario would have split it into 2 variables. permalink fedilink source parent [β] LemoineFairclough@sh.itjust.works 1 point 2 years ago I don't think this is correct. Consider what you see from using sh -c -- 'var="a " && printf "%s\n" "${var}"-z' If "${var}"-z resulted in two arguments instead of one, I'd see "a" and "-z" on different lines, but I see them on the same line, which means they are treated as a single argument. permalink fedilink source parent
[β] venusenvy47@lemdro.id 1 point 3 years ago (1 child) Would a space at the end of the variable be ignored in the second one, though? permalink fedilink source parent hideshow 2 child comments replies: [β] DoomBot5@lemmy.world 1 point 2 years ago It would still be considered a single variable because the entire string is quoted. The first scenario would have split it into 2 variables. permalink fedilink source parent
[β] DoomBot5@lemmy.world 1 point 2 years ago It would still be considered a single variable because the entire string is quoted. The first scenario would have split it into 2 variables. permalink fedilink source parent
[β] LemoineFairclough@sh.itjust.works 1 point 2 years ago I don't think this is correct. Consider what you see from using sh -c -- 'var="a " && printf "%s\n" "${var}"-z' If "${var}"-z resulted in two arguments instead of one, I'd see "a" and "-z" on different lines, but I see them on the same line, which means they are treated as a single argument. permalink fedilink source parent