Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Having problem with batch file

Name: Anonymous 2009-03-27 17:51

@echo off

:start

echo.
echo Computer: Which topic do you wish to talk about?

set /p topic=

if %topic%.==. (echo Computer: Don't just press enter without typing anything!) && (echo           I'll ask again.) && (goto start)

FINDSTR /C:"%topic%" responses.bat > NUL || goto unfamiliar
call responses.bat

----------------------------

So that's the start of my code. I'm trying to check for a null string, to make it complain if you just press enter without inputting anything.

It works for just pressing enter - but there's an unfortunate side-effect. If you enter in anything with a space (such as "James bond" , without quotes), it exits. It's not following goto end or anything like that, because I have a pause command right after :end.

I know it's definitely the line with the 'if' that's causing the problems, and not any other line. I think.

Help a noob out?

Name: Anonymous 2009-03-27 17:58

Enclose the comparands in quotes.

Name: Anonymous 2009-03-27 18:07

download cygwin. learn bash

Name: Anonymous 2009-03-27 18:47

>>2
Correct
>>3
download powershell. learn powerhell

Name: Anonymous 2009-03-27 18:53

>>4
Powershell looks interesting. How empowering is it when compared to bash?

Name: Anonymous 2009-03-27 18:57

>>5
It's severely hampered by the fact you're still running Windows.

Name: Anonymous 2009-03-27 19:00

>>6
Read >>3,4

Name: Anonymous 2009-03-27 19:04

>>5
PoSh does everything you'd expect from a Perl-descended scripting language (which it is, only it looks a lot less like line noise), has a large number of convenient operating system hooks -- cmdlets -- and if all else fails, you can get at the .Net APIs too.

It also builds on the conventional *nix idea of piping bytestreams between commands, by incorporating a model of streaming datastructures between commands (so rather than having a model where you might pipe the output of ls -al into some awk magic to parse each entry when e.g. sorting out all files above a given size, a Get-ChildItem would give a bunch of File structures, whose SIze you could filter on directly.

Name: Anonymous 2009-03-27 19:51

>>8
It also builds on the conventional MS idea of making everything ten times more verbose than necessary, and introducing capital letters everywhere for no damn reason.

I'll take ls -l|awk '{if ($5 > 10000) print $0}' any day over having to type shit like Get-ChildItem. MS still haven't figured out that typing less is better.

Name: Anonymous 2009-03-27 20:01

>>9
You actually typed more.

Name: Anonymous 2009-03-27 20:32

>>7
Read SICP.

Name: Anonymous 2009-03-27 20:35

OP Here.

replaced this
if %topic%.==.
with this
if "%topic%."=="."

>>2
Thanks loads.

I have little knowledge of what most of you guys are talking about, but I suppose that's why I'm the one asking the questions. :P

Name: 8 2009-03-27 20:37

>>9
It's not quite so verbose as you imagine. By default, ls and dir are an alias for Get-ChildItem. Most of the built-in commands have a sensible alias. Example:

ls | where {$_.Length -gt 10000} (Yes, `Length' for some strange reason.)

But, I can't say that I like PowerShell. I just opened PowerShell and it took over 5 seconds to load. But even if it did load quickly, it would still feel clunky most of the time.

And then there's some just downright stupid shit:
PS K:\> pwd

Path
----
K:\

PS K:\>

Name: Anonymous 2009-03-27 20:54

>>9
You suck at awk.

Name: Anonymous 2009-03-28 1:21

>>14
You suck at sucking dick.

Name: Anonymous 2009-03-28 1:21

>>12
Read SICP.

Name: Anonymous 2009-03-28 4:15

>>12
Dots not needed -- replace this
if "%topic%."=="."
with this
if "%topic%"==""

Name: Anonymous 2009-03-28 4:23

>>9
They recognised the problem with typing when you're doing one-shot stuff at the command line, so there's aliases and tab completion too.

For scripts that stay around and are maintained, so are write-rarely&read-often, the more narrative names are an aid to the reader.

Name: Anonymous 2010-12-17 1:36

Are you GAY?
Are you a NIGGER?
Are you a GAY NIGGER?

If you answered "Yes" to all of the above questions, then GNAA (GAY NIGGER ASSOCIATION OF AMERICA) might be exactly what you've been looking for!

Name: Anonymous 2010-12-22 4:40

Don't change these.
Name: Email:
Entire Thread Thread List