DOS shell command substitution?

Programming, for all ages and all languages.
Post Reply
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

DOS shell command substitution?

Post by Solar »

I know this is a long shot, but is there any way to do something similar to Unix backticks / $() under MS-DOS?

Please don't laugh, but I'd need something like that for work. I'd really hate to do this with temporary files.
Every good solution is obvious once you've found it.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post by Solar »

Forget it... after much googling, I came to realize the full extend of incompetence that is MS-DOS... you can't do command substitution, you can't even read in a temporary file into a variable without major stunts, and then only if the temporary file is one line only (which must be less than 127 characters)... oi, crickey... :roll:
Every good solution is obvious once you've found it.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Post by Candy »

Solar wrote:Forget it... after much googling, I came to realize the full extend of incompetence that is MS-DOS... you can't do command substitution, you can't even read in a temporary file into a variable without major stunts, and then only if the temporary file is one line only (which must be less than 127 characters)... oi, crickey... :roll:
You can't even use proper pipelines.

You could of course try using djgpp to compile bash, using some dos-windows subform of bash or using / porting another shell that does support it. Backticks would be a good idea for it, since that at least doesn't require having multiple commands running at the same time. Did you try their && logic already? Iirc it came down to "if the first command fails the second doesn't run, so it doesn't fail, so it succeeds, so the third command is run as long as the second command succeeds or the first fails" which wasn't really what I had intended with &&.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post by Solar »

Candy wrote:You could of course try using djgpp to compile bash...
No go. It's native tools or nothing (production environment constraints), which also rules out Perl script. And I won't start writing a C prog for this stuff... well, the script will look ugly and be much less elegant than I prefer my code to be, but it's unlikely anyone else will use it anyway... ;-)
Every good solution is obvious once you've found it.
Post Reply