DOS equivalent of ${variable}

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
doscode
Posts: 175
Joined: 15 Feb 2012 14:02

DOS equivalent of ${variable}

#1 Post by doscode » 11 Apr 2012 15:44

How to write linux bash

Code: Select all

${path}
syntax in DOS?

Code: Select all

set "path=mypath"
convert image.jpg -resize 50% ${path}image.png

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: DOS equivalent of ${variable}

#2 Post by Ed Dyreen » 11 Apr 2012 23:31

'
save as 'batch.CMD' and doubleClick to see instructions of set

Code: Select all

@echo off &set /? |more

doscode
Posts: 175
Joined: 15 Feb 2012 14:02

Re: DOS equivalent of ${variable}

#3 Post by doscode » 12 Apr 2012 00:21

Should I use SET /A alias?

Liviu
Expert
Posts: 470
Joined: 13 Jan 2012 21:24

Re: DOS equivalent of ${variable}

#4 Post by Liviu » 12 Apr 2012 01:09

In addition to Ed's excellent advice, see also viewtopic.php?p=14700#p14700 and other previous posts of your own. PATH is no different from CD or TAB.

doscode
Posts: 175
Joined: 15 Feb 2012 14:02

Re: DOS equivalent of ${variable}

#5 Post by doscode » 13 Apr 2012 01:22

Nobody understands my question? I don't ask how to set global variable PATH.

I ask how to evaluate/perform command and set its output to variable.

I simplified the original code before posting it here

Code: Select all

inname=`convert image -format "%t" info:`
convert image.jpg ..... ${inname}_%d.png
Last edited by doscode on 13 Apr 2012 03:03, edited 3 times in total.

jeb
Expert
Posts: 1041
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: DOS equivalent of ${variable}

#6 Post by jeb » 13 Apr 2012 02:00

Expanding of variables are done with percents.

Code: Select all

inname=`convert image -format "%%t" info:`
convert image.jpg ..... %inname%_%%d.png


You could also use exclamation marks if you use setlocal EnableDelayedExpansion before.

To escape a single percent you have to double it.

Code: Select all

echo 100%%


jeb

doscode
Posts: 175
Joined: 15 Feb 2012 14:02

Re: DOS equivalent of ${variable}

#7 Post by doscode » 13 Apr 2012 02:58

inname is not a command. Somebody told me to use alias command, but that's linux command.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: DOS equivalent of ${variable}

#8 Post by Squashman » 13 Apr 2012 06:05

You cannot directly set the output of a command to a variable in batch files like you can with BASH or other linux shells. Batch doesn't know that that back quote means to execute the command before assigning it to a variable.
You need to put the command inside a FOR /F loop and assign the output of the command to a variable from there.

Post Reply