▲ 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
[–] SpaceNoodle@lemmy.world 88 points 3 years ago* (3 children) find "${HOME}/docs/" You want the full path in quotes so that paths with spaces are handled properly. Brackets are good practice when concatenating strings. permalink fedilink source hideshow 6 child comments replies: [–] Synthead@lemmy.world 7 points 3 years ago (2 children) If the strings don't contain characters that help define a variable, like an underscore, how is it better practice to use curlies? It's it just for consistency? Have you had any style guides or linters critique the use of variables without them? permalink fedilink source parent hideshow 4 child comments replies: [–] RazorsLedge@lemmy.world 24 points 3 years ago* (1 child) foo=ding foobar=dong echo \$foobar Brackets make it explicit what you're trying to do. Do you want "dingbar" or do you want "dong"? I forget what the actual behavior is if you don't use brackets here, because I always use brackets for this reason now permalink fedilink source parent hideshow 2 child comments replies: [–] subtext@lemmy.world 5 points 3 years ago (1 child) I believe the actual behavior here would be printing “dong” as the shell interpreter is greedy in its evaluation of variables. permalink fedilink source parent hideshow 2 child comments replies: [–] vrighter@discuss.tchncs.de 2 points 2 years ago (1 child) the actual behavior here is to echo the literal string "$foobar", because the $ sign is escaped. so no variable expansion will take place at all. permalink fedilink source parent hideshow 2 child comments replies: [–] RazorsLedge@lemmy.world 2 points 2 years ago (2 children) Oh lol. It doesn't show the $ at all on my mobile app till I escaped it permalink fedilink source parent hideshow 4 child comments replies: [–] vrighter@discuss.tchncs.de 2 points 2 years ago ah, so it's up to the client. I'm using jerboa, in this case permalink fedilink source parent [–] rtxn@lemmy.world 1 point 2 years ago (1 child) You should use markdown's inline code (single `backtick`) and block code (triple backtick) tags. They are consistent across most markdown renderers (except Reddit's, which uses four-space indentations (like, who the fuck thought that was a good idea?)) permalink fedilink source parent hideshow 2 child comments replies: [–] RazorsLedge@lemmy.world 1 point 2 years ago I did use triple backticks permalink fedilink source parent [–] SpaceNoodle@lemmy.world 23 points 3 years ago* More than anything, I find that it's a good habit to maintain in order to avoid simple mistakes. It also makes variables easier to spot in code and maintains consistency. permalink fedilink source parent [–] FuglyDuck@lemmy.world 1 point 3 years ago* “Concatenating”…. …. That sounds either exceptionally painful or extremely fun. Quite possibly both… permalink fedilink source parent [–] ArtificialLink@lemmy.ml 1 point 3 years ago (1 child) This shit fucked me up so much when i was learning linux stuff. Especially cause a lot of my file paths had spaces. This is the way. permalink fedilink source parent hideshow 2 child comments replies: [–] ExLisper@linux.community 1 point 2 years ago (1 child) The lesson for me was not to create paths with spaces. There are none in Linux unless you create them. permalink fedilink source parent hideshow 2 child comments replies: [–] ArtificialLink@lemmy.ml 1 point 2 years ago Too late lol. permalink fedilink source parent
[–] Synthead@lemmy.world 7 points 3 years ago (2 children) If the strings don't contain characters that help define a variable, like an underscore, how is it better practice to use curlies? It's it just for consistency? Have you had any style guides or linters critique the use of variables without them? permalink fedilink source parent hideshow 4 child comments replies: [–] RazorsLedge@lemmy.world 24 points 3 years ago* (1 child) foo=ding foobar=dong echo \$foobar Brackets make it explicit what you're trying to do. Do you want "dingbar" or do you want "dong"? I forget what the actual behavior is if you don't use brackets here, because I always use brackets for this reason now permalink fedilink source parent hideshow 2 child comments replies: [–] subtext@lemmy.world 5 points 3 years ago (1 child) I believe the actual behavior here would be printing “dong” as the shell interpreter is greedy in its evaluation of variables. permalink fedilink source parent hideshow 2 child comments replies: [–] vrighter@discuss.tchncs.de 2 points 2 years ago (1 child) the actual behavior here is to echo the literal string "$foobar", because the $ sign is escaped. so no variable expansion will take place at all. permalink fedilink source parent hideshow 2 child comments replies: [–] RazorsLedge@lemmy.world 2 points 2 years ago (2 children) Oh lol. It doesn't show the $ at all on my mobile app till I escaped it permalink fedilink source parent hideshow 4 child comments replies: [–] vrighter@discuss.tchncs.de 2 points 2 years ago ah, so it's up to the client. I'm using jerboa, in this case permalink fedilink source parent [–] rtxn@lemmy.world 1 point 2 years ago (1 child) You should use markdown's inline code (single `backtick`) and block code (triple backtick) tags. They are consistent across most markdown renderers (except Reddit's, which uses four-space indentations (like, who the fuck thought that was a good idea?)) permalink fedilink source parent hideshow 2 child comments replies: [–] RazorsLedge@lemmy.world 1 point 2 years ago I did use triple backticks permalink fedilink source parent [–] SpaceNoodle@lemmy.world 23 points 3 years ago* More than anything, I find that it's a good habit to maintain in order to avoid simple mistakes. It also makes variables easier to spot in code and maintains consistency. permalink fedilink source parent
[–] RazorsLedge@lemmy.world 24 points 3 years ago* (1 child) foo=ding foobar=dong echo \$foobar Brackets make it explicit what you're trying to do. Do you want "dingbar" or do you want "dong"? I forget what the actual behavior is if you don't use brackets here, because I always use brackets for this reason now permalink fedilink source parent hideshow 2 child comments replies: [–] subtext@lemmy.world 5 points 3 years ago (1 child) I believe the actual behavior here would be printing “dong” as the shell interpreter is greedy in its evaluation of variables. permalink fedilink source parent hideshow 2 child comments replies: [–] vrighter@discuss.tchncs.de 2 points 2 years ago (1 child) the actual behavior here is to echo the literal string "$foobar", because the $ sign is escaped. so no variable expansion will take place at all. permalink fedilink source parent hideshow 2 child comments replies: [–] RazorsLedge@lemmy.world 2 points 2 years ago (2 children) Oh lol. It doesn't show the $ at all on my mobile app till I escaped it permalink fedilink source parent hideshow 4 child comments replies: [–] vrighter@discuss.tchncs.de 2 points 2 years ago ah, so it's up to the client. I'm using jerboa, in this case permalink fedilink source parent [–] rtxn@lemmy.world 1 point 2 years ago (1 child) You should use markdown's inline code (single `backtick`) and block code (triple backtick) tags. They are consistent across most markdown renderers (except Reddit's, which uses four-space indentations (like, who the fuck thought that was a good idea?)) permalink fedilink source parent hideshow 2 child comments replies: [–] RazorsLedge@lemmy.world 1 point 2 years ago I did use triple backticks permalink fedilink source parent
[–] subtext@lemmy.world 5 points 3 years ago (1 child) I believe the actual behavior here would be printing “dong” as the shell interpreter is greedy in its evaluation of variables. permalink fedilink source parent hideshow 2 child comments replies: [–] vrighter@discuss.tchncs.de 2 points 2 years ago (1 child) the actual behavior here is to echo the literal string "$foobar", because the $ sign is escaped. so no variable expansion will take place at all. permalink fedilink source parent hideshow 2 child comments replies: [–] RazorsLedge@lemmy.world 2 points 2 years ago (2 children) Oh lol. It doesn't show the $ at all on my mobile app till I escaped it permalink fedilink source parent hideshow 4 child comments replies: [–] vrighter@discuss.tchncs.de 2 points 2 years ago ah, so it's up to the client. I'm using jerboa, in this case permalink fedilink source parent [–] rtxn@lemmy.world 1 point 2 years ago (1 child) You should use markdown's inline code (single `backtick`) and block code (triple backtick) tags. They are consistent across most markdown renderers (except Reddit's, which uses four-space indentations (like, who the fuck thought that was a good idea?)) permalink fedilink source parent hideshow 2 child comments replies: [–] RazorsLedge@lemmy.world 1 point 2 years ago I did use triple backticks permalink fedilink source parent
[–] vrighter@discuss.tchncs.de 2 points 2 years ago (1 child) the actual behavior here is to echo the literal string "$foobar", because the $ sign is escaped. so no variable expansion will take place at all. permalink fedilink source parent hideshow 2 child comments replies: [–] RazorsLedge@lemmy.world 2 points 2 years ago (2 children) Oh lol. It doesn't show the $ at all on my mobile app till I escaped it permalink fedilink source parent hideshow 4 child comments replies: [–] vrighter@discuss.tchncs.de 2 points 2 years ago ah, so it's up to the client. I'm using jerboa, in this case permalink fedilink source parent [–] rtxn@lemmy.world 1 point 2 years ago (1 child) You should use markdown's inline code (single `backtick`) and block code (triple backtick) tags. They are consistent across most markdown renderers (except Reddit's, which uses four-space indentations (like, who the fuck thought that was a good idea?)) permalink fedilink source parent hideshow 2 child comments replies: [–] RazorsLedge@lemmy.world 1 point 2 years ago I did use triple backticks permalink fedilink source parent
[–] RazorsLedge@lemmy.world 2 points 2 years ago (2 children) Oh lol. It doesn't show the $ at all on my mobile app till I escaped it permalink fedilink source parent hideshow 4 child comments replies: [–] vrighter@discuss.tchncs.de 2 points 2 years ago ah, so it's up to the client. I'm using jerboa, in this case permalink fedilink source parent [–] rtxn@lemmy.world 1 point 2 years ago (1 child) You should use markdown's inline code (single `backtick`) and block code (triple backtick) tags. They are consistent across most markdown renderers (except Reddit's, which uses four-space indentations (like, who the fuck thought that was a good idea?)) permalink fedilink source parent hideshow 2 child comments replies: [–] RazorsLedge@lemmy.world 1 point 2 years ago I did use triple backticks permalink fedilink source parent
[–] vrighter@discuss.tchncs.de 2 points 2 years ago ah, so it's up to the client. I'm using jerboa, in this case permalink fedilink source parent
[–] rtxn@lemmy.world 1 point 2 years ago (1 child) You should use markdown's inline code (single `backtick`) and block code (triple backtick) tags. They are consistent across most markdown renderers (except Reddit's, which uses four-space indentations (like, who the fuck thought that was a good idea?)) permalink fedilink source parent hideshow 2 child comments replies: [–] RazorsLedge@lemmy.world 1 point 2 years ago I did use triple backticks permalink fedilink source parent
[–] RazorsLedge@lemmy.world 1 point 2 years ago I did use triple backticks permalink fedilink source parent
[–] SpaceNoodle@lemmy.world 23 points 3 years ago* More than anything, I find that it's a good habit to maintain in order to avoid simple mistakes. It also makes variables easier to spot in code and maintains consistency. permalink fedilink source parent
[–] FuglyDuck@lemmy.world 1 point 3 years ago* “Concatenating”…. …. That sounds either exceptionally painful or extremely fun. Quite possibly both… permalink fedilink source parent
[–] ArtificialLink@lemmy.ml 1 point 3 years ago (1 child) This shit fucked me up so much when i was learning linux stuff. Especially cause a lot of my file paths had spaces. This is the way. permalink fedilink source parent hideshow 2 child comments replies: [–] ExLisper@linux.community 1 point 2 years ago (1 child) The lesson for me was not to create paths with spaces. There are none in Linux unless you create them. permalink fedilink source parent hideshow 2 child comments replies: [–] ArtificialLink@lemmy.ml 1 point 2 years ago Too late lol. permalink fedilink source parent
[–] ExLisper@linux.community 1 point 2 years ago (1 child) The lesson for me was not to create paths with spaces. There are none in Linux unless you create them. permalink fedilink source parent hideshow 2 child comments replies: [–] ArtificialLink@lemmy.ml 1 point 2 years ago Too late lol. permalink fedilink source parent