ALIAS with multiple commands?

Apr 17, 2009
9
2
Wildomar, CA
kb6ojs.com
Ran into a head-scratcher tonight, can't find it in the help file so thought I'd pop in here with a question:

I'm trying to create an ALIAS that runs three commands:

date /t "%F"
time /t "%T"
free C:


Basically giving a date/time stamp on the output of the command to show free space on the C: drive. What I tried to do, and which didn't work, was:

ALIAS fcx = *date /t "%F" && time /t "%T" && free C:

(Note: I have an alias fc which just has free c: as the sole command. fcx is "experimental."

Now, I may be showing some "Linux-ese" here by using the && to put multiple commands on the same line, but I don't remember what the delineator is between commands on the same line, one which the system won't apparently interpret as "commenting-out" everything after.

Recommendations?

(Note: batch-file commands are something I haven't done very much with for several years. I used to be VERY good at it, back in my DOS days, and between that and dBASE I could make a computer do just about do anything I wanted it to do! Time has taken its toll on my brain cells, however. I'm thinking some of this stuff was stored in the brain cells that were damaged due to the excesses of my intemperate youth....)

Many thanks in advance for any assistance/recommendations you can provide. //Steve//
 
Apr 18, 2014
264
9
The default command separator is a single ampersand, although you can change it if you wish; look at the help for Setdos /c or the Option command.

To stop the parser interpreting the individual commands in an alias that you create at the command line you need to enclose it in single back quotes. I can't work out myself how to use the %F format options with Date, but you can use /f4 to get the same format, and I think the default output from the Time command is the same as %T anyway. So try this


Code:
alias fcx=`*date /f4 /t & time /t & free c:`
 
  • Like
Reactions: ebbe
May 20, 2008
10,939
84
Syracuse, NY, USA
"&&" works also; it's the conditional command separator. I think kb6ojs needed the backquotes. RogerB, what problem do you have with the %F format?

Code:
v:\> ALIAS fcx=`*date /t "%F" && time /t "%T" && free C:`

v:\> fcx
Tue 24-11-2020
12:54:51

 Volume in drive C is OS           Serial number is 547b:a92d
     510,240,223,232 bytes total disk space
      62,335,086,592 bytes used
     447,905,136,640 bytes free
                12.2 % in use
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,311
78
Albuquerque, NM
prospero.unm.edu
"&&" works also; it's the conditional command separator. I think kb6ojs needed the backquotes. RogerB, what problem do you have with the %F format?

Code:
v:\> ALIAS fcx=`*date /t "%F" && time /t "%T" && free C:`

v:\> fcx
Tue 24-11-2020
12:54:51

Volume in drive C is OS           Serial number is 547b:a92d
     510,240,223,232 bytes total disk space
      62,335,086,592 bytes used
     447,905,136,640 bytes free
                12.2 % in use

First, he needs to double the percent sign; otherwise TCC tries to expand an environment variable F. Second, don't specify /T when you're using a custom format. I don't know why, but the two don't play nicely together.

Code:
date "%%F"
 
May 20, 2008
10,939
84
Syracuse, NY, USA
First, he needs to double the percent sign; otherwise TCC tries to expand an environment variable F. Second, don't specify /T when you're using a custom format. I don't know why, but the two don't play nicely together.

Code:
date "%%F"
Did you try that, Charles? The "/T" seems necessary here.

Code:
v:\> date "%%f"
TCC: (Sys) The parameter is incorrect.
 "2020-11-24"

v:\> date /t "%%f"
Tue 24-11-2020
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,311
78
Albuquerque, NM
prospero.unm.edu
Did you try that, Charles? The "/T" seems necessary here.

Code:
v:\> date "%%f"
TCC: (Sys) The parameter is incorrect.
"2020-11-24"

v:\> date /t "%%f"
Tue 24-11-2020

The %%F needs to be uppercase. @DATEFMT's tokens are case-sensitive. %%F is the date in ISO format; %%f is undefined and gives an error.
 
Apr 17, 2009
9
2
Wildomar, CA
kb6ojs.com
Wow, LOTS of awesome information on the subject! I know this will fix my issue, so I'll print this all out and get cracking on the problem. I appreciate the access to the collective knowledge here (wait, that sounds like something Borg-related out of Star Trek, maybe I shouldn't go there....) :)

Thanks again. //Steve//