27 May 2020, 12:13 | #1 |
With MMU and FPU!
Join Date: Mar 2015
Location: On your mainboard
Posts: 270
|
Read file and compare it to a string
I want to compare the contents of a file against a string in an AmigaDOS script. Let's say I want to check if the file ram:test contains the string "Hello World". I've tried to do it like this but it doesn't work:
Code:
echo >ram:test "Hello World" set foo <ram:test if $foo eq "Hello World" echo "Yep!" else echo "Nope!" endif |
27 May 2020, 12:23 | #2 |
It's coming back!
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
|
Carriage return from the echo? Can you add an echo $foo to confirm?
|
27 May 2020, 12:32 | #3 |
Registered User
Join Date: Nov 2004
Location: Germany
Posts: 629
|
Try echo $foo to see what it contains ?!
(edit while i was testing it on winuae, someone answered XD) |
27 May 2020, 12:37 | #4 |
With MMU and FPU!
Join Date: Mar 2015
Location: On your mainboard
Posts: 270
|
WTF... $foo contains "<ram:test" so redirection doesn't seem to work at all Is there any other way?
|
27 May 2020, 12:49 | #5 |
Registered User
Join Date: Nov 2004
Location: Germany
Posts: 629
|
what if you save the file as, well use this:
echo >ram:test set foo Hello World then you do execute ram:test echo $foo it works if you do it in the cli, i'm not sure if it works in/as the batch file. Last edited by Dan; 27 May 2020 at 13:02. |
27 May 2020, 13:02 | #6 | |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 6,985
|
Quote:
So set <ram:test foo should work. Only since Kick 2.0 redirection is allowed anywhere in the command line, but only if the command does not have a /f argument which takes everything until the end of the line. |
|
27 May 2020, 13:02 | #7 | |
With MMU and FPU!
Join Date: Mar 2015
Location: On your mainboard
Posts: 270
|
Quote:
|
|
27 May 2020, 13:04 | #8 | |
With MMU and FPU!
Join Date: Mar 2015
Location: On your mainboard
Posts: 270
|
Quote:
Code:
echo >ram:test "Hello World" set <ram:test foo echo $foo if $foo eq "Hello World" echo "OK!" else echo "Nope!" endif |
|
27 May 2020, 13:05 | #9 |
Registered User
Join Date: Nov 2004
Location: Germany
Posts: 629
|
I see, i assumed you are writing this text file, like in your first example, from the batch file.
|
27 May 2020, 13:06 | #10 |
With MMU and FPU!
Join Date: Mar 2015
Location: On your mainboard
Posts: 270
|
|
27 May 2020, 13:09 | #11 |
Registered User
Join Date: Nov 2004
Location: Germany
Posts: 629
|
this textfile, which you want to check, does it contain only 1 line of text ?
how about this ? https://wiki.amigaos.net/wiki/AmigaO...ference#SEARCH |
27 May 2020, 13:18 | #12 |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 6,985
|
You forgot one important thing: set reads the value from the command line, it does not read from the input stream. Therefore redirecting the input stream does not affect it.
There is a trick, though: set >nil: <ram:test foo ? The ? makes the command print its template and wait for input. This way you can read from the redirected input stream. |
27 May 2020, 13:21 | #13 |
With MMU and FPU!
Join Date: Mar 2015
Location: On your mainboard
Posts: 270
|
Cool, that's a nifty trick! You are my hero @thomas!
So here is the final script (I also had to add quotes around "$foo" to make it work): Code:
echo >ram:test "Hello World" set >nil: <ram:test foo ? if "$foo" eq "Hello World" echo "OK!" else echo "Nope!" endif |
27 May 2020, 16:19 | #14 |
This cat is no more
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,162
|
AFAIR you can also use PIPE: to avoid creating a file.
But once you tried modern scripting languages, Amiga csh is just frustrating. |
27 May 2020, 16:55 | #15 |
Registered User
Join Date: Oct 2009
Location: Germany
Posts: 3,303
|
I would say if you are not forced to use AmigaDOS then don't use it.
|
29 May 2020, 05:51 | #16 |
Registered User
Join Date: Feb 2007
Location: Melbourne, Australia
Age: 41
Posts: 3,772
|
Would be nice to have a modern version of zsh for Amiga. The latest version on Aminet is from 1996.
|
08 September 2021, 19:03 | #17 |
Registered User
Join Date: Apr 2012
Location: Cyberspace
Posts: 57
|
You could also use backticks:
echo noline "Hello World" > ram:test set foo=`type ram:test` |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Disk \ ADF Compare | felixkat | request.Apps | 46 | 28 March 2021 00:00 |
[blitz] how to set initial variables read from a file | peceha | Coders. Blitz Basic | 3 | 20 September 2019 11:56 |
overscan and mouse settings option to be read from external file | _psy | project.WHDLoad | 5 | 15 April 2015 13:30 |
What version of DX did the AGA compare to? | methodman | Retrogaming General Discussion | 8 | 22 May 2010 09:02 |
|
|