Our server costs ~$56 per month to run. Please consider donating or becoming a Patron to help keep the site running. Help us gain new members by following us on Twitter and liking our page on Facebook!
Current time: April 16, 2024, 12:07 am

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Writing scripts for UNIX-like operating systems
#11
RE: Writing scripts for UNIX-like operating systems
(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.
Reply
#12
RE: Writing scripts for UNIX-like operating systems
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.
Reply
#13
RE: Writing scripts for UNIX-like operating systems
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
Reply
#14
RE: Writing scripts for UNIX-like operating systems
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.
Reply
#15
RE: Writing scripts for UNIX-like operating systems
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
Reply
#16
RE: Writing scripts for UNIX-like operating systems
So, is it just me, or is shell scripting one of the most frustrating kinds of programming, way more frustrating than front-end development?
Reply
#17
RE: Writing scripts for UNIX-like operating systems
It's just you.
[Image: extraordinarywoo-sig.jpg]
Reply
#18
RE: Writing scripts for UNIX-like operating systems
(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
Reply
#19
RE: Writing scripts for UNIX-like operating systems
(January 21, 2023 at 2:33 pm)Angrboda Wrote: It's just you.

Have you tried writing shell scripts?
Reply
#20
RE: Writing scripts for UNIX-like operating systems
(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.
Reply



Possibly Related Threads...
Thread Author Replies Views Last Post
  License for operating social media Fake Messiah 2 746 December 16, 2022 at 10:41 pm
Last Post: Rev. Rye
  TempleOS: a Christian Operating System Rev. Rye 5 1285 December 23, 2018 at 12:32 pm
Last Post: Rev. Rye
  Operating systems Wars! Sterben 60 4708 March 14, 2017 at 8:49 pm
Last Post: Sterben
  Using SSDs for dual boot systems emjay 9 1407 November 8, 2016 at 7:33 pm
Last Post: emjay



Users browsing this thread: 1 Guest(s)