It has nothing to do with bash specifically - other shells like sh, csh, tcsh, zsh, etc. are the same. Whitespace in UNIX is just that way by design. And it’s been a long while since I used a Windows CLI but they were that way too - plus added all that weirdness about ~1 at the ends of filenames, and Mac OSX also. So not even just UNIX, but it’s how the CLIs tend to work, where whitespace acts as the “delimiter” between arguments sent to a program.
program_name arg1 arg2 arg3 arg4
So if you use whitespace like “cp file 1 file 2”, the CLI sends arg1=“file”, arg2=“1”, arg3=“file”, arg4=“2”, rather than arg1=“file 1” and arg2=“file 2”. These are just the foundational rules of how CLIs work - a computer can’t read your mind, and this is how you precisely tell it what you want, within this highly rigid framework to avoid misunderstandings.
The alternative is to use a GUI, so like see file, drag file, and ofc that has its own set of tradeoffs good and bad.
Yeah, for this reason, lots of full-fledged programming languages actually make you specify the arguments as a list of strings directly, so for example:
It’s a subset of the standard delimiter problem: if I want to use the delimiter inside of an entry, can I even do that and if so then how?
e.g. in comma-delimited lists you could “escape” the commas individually, or encapsulate each entry inside quotes, or provide each entry by name, etc. - all of which significantly complicates the retrieval process by adding greater complexity to decide on rules determining how it all works (like if by name, then what if the user [stupidly? on purpose?] provides multiple entries with the same name - do subsequent ones overwrite the earlier ones or their contents get appended to the end and if the latter, is any separation provided between them? and on and on it goes):
item1,item2,item3
“Denver, CO”,“New York, NY”,Miami/, FL
“Lastname, Firstname”,Lastname/, Firstname
item1=“Denver, CO”, item2=“New York, NY”
Common English has issues with this too like is a list with “John, Marsha, Barbie and Ken” 4 entries or just 3 where the latter is a pairing? (leading to Oxford comma discussion:-P it is very important though bc while while individual people may have similar needs like food, pairings may have different constraints like if they drive together then they need less parking space)
So this delimiter issue is not even specific to CLIs, nor even computers in general - it is a universal problem with any communication system.
It has nothing to do with bash specifically - other shells like sh, csh, tcsh, zsh, etc. are the same. Whitespace in UNIX is just that way by design. And it’s been a long while since I used a Windows CLI but they were that way too - plus added all that weirdness about ~1 at the ends of filenames, and Mac OSX also. So not even just UNIX, but it’s how the CLIs tend to work, where whitespace acts as the “delimiter” between arguments sent to a program.
program_name arg1 arg2 arg3 arg4
So if you use whitespace like “cp file 1 file 2”, the CLI sends arg1=“file”, arg2=“1”, arg3=“file”, arg4=“2”, rather than arg1=“file 1” and arg2=“file 2”. These are just the foundational rules of how CLIs work - a computer can’t read your mind, and this is how you precisely tell it what you want, within this highly rigid framework to avoid misunderstandings.
The alternative is to use a GUI, so like see file, drag file, and ofc that has its own set of tradeoffs good and bad.
Yeah, for this reason, lots of full-fledged programming languages actually make you specify the arguments as a list of strings directly, so for example:
Command::new("cp") .args(["file 1", "file 2”])
It’s a subset of the standard delimiter problem: if I want to use the delimiter inside of an entry, can I even do that and if so then how?
e.g. in comma-delimited lists you could “escape” the commas individually, or encapsulate each entry inside quotes, or provide each entry by name, etc. - all of which significantly complicates the retrieval process by adding greater complexity to decide on rules determining how it all works (like if by name, then what if the user [stupidly? on purpose?] provides multiple entries with the same name - do subsequent ones overwrite the earlier ones or their contents get appended to the end and if the latter, is any separation provided between them? and on and on it goes):
Common English has issues with this too like is a list with “John, Marsha, Barbie and Ken” 4 entries or just 3 where the latter is a pairing? (leading to Oxford comma discussion:-P it is very important though bc while while individual people may have similar needs like food, pairings may have different constraints like if they drive together then they need less parking space)
So this delimiter issue is not even specific to CLIs, nor even computers in general - it is a universal problem with any communication system.