Posts: 30595
Threads: 204
Joined: July 19, 2011
Reputation:
141
RE: Writing scripts for UNIX-like operating systems
January 13, 2023 at 10:01 pm
(January 13, 2023 at 5:52 pm)BrianSoddingBoru4 Wrote: Have you tried heating it to a cherry-red colour and then beating it with a hammer?
Boru
I can't say that works on unix scripts, but it does work on people.
Posts: 2020
Threads: 133
Joined: July 26, 2017
Reputation:
5
RE: Writing scripts for UNIX-like operating systems
January 16, 2023 at 10:58 am
I barely managed to get the NodeJS version check to work on Git Bash on Windows. Before NodeJS outputted the error message " stdout is not a tty" instead of outputting the version number. Here is what the shell script to use the AEC-to-WebAssembly compiler looks like now:
Code: if [ $(command -v git > /dev/null 2>&1 ; echo $?) -eq 0 ]
then
git clone https://github.com/FlatAssembler/AECforWebAssembly.git
cd AECforWebAssembly
elif [ $(command -v wget > /dev/null 2>&1 ; echo $?) -eq 0 ]
then
mkdir AECforWebAssembly
cd AECforWebAssembly
wget https://github.com/FlatAssembler/AECforWebAssembly/archive/refs/heads/master.zip
unzip master.zip
cd AECforWebAssembly-master
else
mkdir AECforWebAssembly
cd AECforWebAssembly
curl -o AECforWebAssembly.zip -L https://github.com/FlatAssembler/AECforWebAssembly/archive/refs/heads/master.zip # Without the "-L", "curl" will store HTTP Response headers of redirects to the ZIP file instead of the actual ZIP file.
unzip AECforWebAssembly.zip
cd AECforWebAssembly-master
fi
if [ $(command -v g++ > /dev/null 2>&1 ; echo $?) -eq 0 ]
then
g++ -std=c++11 -o aec AECforWebAssembly.cpp # "-std=c++11" should not be necessary for newer versions of "g++". Let me know if it is, as that probably means I disobeyed some new C++ standard (say, C++23).
else
clang++ -o aec AECforWebAssembly.cpp
fi
cd analogClock
../aec analogClock.aec
npx -p wabt wat2wasm analogClock.wat
if [ "$OS" = "Windows_NT" ] # https://stackoverflow.com/a/75125384/8902065
# https://www.reddit.com/r/bash/comments/10cip05/comment/j4h9f0x/?utm_source=share&utm_medium=web2x&context=3
then
node_version=$(node.exe -v)
else # We are presumably running on an UNIX-like system, where storing output of some program into a variable works as expected.
node_version=$(node -v)
fi
# "node -v" outputs version in the format "v18.12.1"
node_version=${node_version:1} # Remove 'v' at the beginning
node_version=${node_version%\.*} # Remove trailing ".*".
node_version=${node_version%\.*} # Remove trailing ".*".
node_version=$(($node_version)) # Convert the NodeJS version number from a string to an integer.
if [ $node_version -lt 11 ]
then
echo "NodeJS version is lower than 11 (it is $node_version), you will probably run into trouble!"
fi
node analogClock
You can see the latest version on my blog.
Posts: 2020
Threads: 133
Joined: July 26, 2017
Reputation:
5
RE: Writing scripts for UNIX-like operating systems
January 17, 2023 at 12:55 pm
I have modified the shell script to compile Analog Clock for x86, so that it might be able to run on Windows. Here is what it looks like now:
Code: mkdir ArithmeticExpressionCompiler
cd ArithmeticExpressionCompiler
if [ $(command -v wget > /dev/null 2>&1 ; echo $?) -eq 0 ] # Check if "wget" exists, see those StackOverflow answers for more details:
# https://stackoverflow.com/a/75103891/8902065
# https://stackoverflow.com/a/75103209/8902065
then
wget https://flatassembler.github.io/Duktape.zip
else
curl -o Duktape.zip https://flatassembler.github.io/Duktape.zip
fi
unzip Duktape.zip
if [ $(command -v clang > /dev/null 2>&1 ; echo $?) -eq 0 ] # We prefer "clang" to "gcc" because... what if somebody tries to run this in CygWin terminal? GCC will not work then, CLANG might.
then
c_compiler="clang"
else
c_compiler="gcc"
fi
$c_compiler -o aec aec.c duktape.c -lm # The linker that comes with recent versions of Debian Linux insists that "-lm" is put AFTER the source files, or else it outputs some confusing error message.
if [ "$OS" = "Windows_NT" ]
then
./aec analogClockForWindows.aec
$c_compiler -o analogClockForWindows analogClockForWindows.s -m32
./analogClockForWindows
else
./aec analogClock.aec
$c_compiler -o analogClock analogClock.s -m32
./analogClock
fi
Posts: 2020
Threads: 133
Joined: July 26, 2017
Reputation:
5
RE: Writing scripts for UNIX-like operating systems
January 19, 2023 at 12:42 am
Well, I guess the shell scripts are good enough to be added to READMEs ( https://github.com/FlatAssembler/Arithme...ler#readme https://github.com/FlatAssembler/AECforW...ell-script), Arithmetic Expression Compiler web-page ( https://flatassembler.github.io/compiler.html) and the Analog Clock example on the web ( https://flatassembler.github.io/analogClock). Now they are difficult to change.
Posts: 2020
Threads: 133
Joined: July 26, 2017
Reputation:
5
RE: Writing scripts for UNIX-like operating systems
January 19, 2023 at 4:00 pm
(This post was last modified: January 19, 2023 at 4:23 pm by BrianSoddingBoru4.)
Writing shell scripts has left a very bad impression on me. I have written two short scripts, and I have had to ask no less than three StackOverflow questions (Fortunately, none of them reduced my reputation, and one of them received two upvotes.). One would think that checking whether a program with some name is available is one of the most common things one would like to do in a shell script. Nonetheless, doing that is very complicated. And two times in two short scripts, I had to rely on truly mysterious fixes. I've written a rant about it on my blog:
Administrator Notice Removed blog rant, per Rule 1, bullet point 3. Do NOT do this again.
Boru
Posts: 2020
Threads: 133
Joined: July 26, 2017
Reputation:
5
RE: Writing scripts for UNIX-like operating systems
January 21, 2023 at 2:26 pm
So, is it just me, or is shell scripting one of the most frustrating kinds of programming, way more frustrating than front-end development?
Posts: 28330
Threads: 114
Joined: February 22, 2011
Reputation:
159
RE: Writing scripts for UNIX-like operating systems
January 21, 2023 at 2:33 pm
It's just you.
Posts: 44046
Threads: 529
Joined: July 24, 2013
Reputation:
109
RE: Writing scripts for UNIX-like operating systems
January 21, 2023 at 3:13 pm
(January 21, 2023 at 2:26 pm)FlatAssembler Wrote: So, is it just me, or is shell scripting one of the most frustrating kinds of programming, way more frustrating than front-end development?
People are generally frustrated by things they’re not good at.
Boru
‘But it does me no injury for my neighbour to say there are twenty gods or no gods. It neither picks my pocket nor breaks my leg.’ - Thomas Jefferson
Posts: 2020
Threads: 133
Joined: July 26, 2017
Reputation:
5
RE: Writing scripts for UNIX-like operating systems
January 23, 2023 at 1:26 am
(January 21, 2023 at 2:33 pm)Angrboda Wrote: It's just you.
Have you tried writing shell scripts?
Posts: 2020
Threads: 133
Joined: July 26, 2017
Reputation:
5
RE: Writing scripts for UNIX-like operating systems
January 23, 2023 at 1:29 am
(January 21, 2023 at 3:13 pm)BrianSoddingBoru4 Wrote: (January 21, 2023 at 2:26 pm)FlatAssembler Wrote: So, is it just me, or is shell scripting one of the most frustrating kinds of programming, way more frustrating than front-end development?
People are generally frustrated by things they’re not good at.
Boru I don't remember being nearly as frustrated when making my PacMan in JavaScript or my website. Sure, I ran into a problem that "clientWidth" and "clientHeight" didn't work on SVG elements in Firefox, but I immediately thought of a simple work-around.
|