Solved Should I write all of my scripts in JavaScript?

  • Thread starter Deleted member 63539
  • Start date
Admittedly I am running a fairly old version of FreeBSD on this machine but Lua doesn't seem to be on here.

They put it in the boot loader to replace forth, and since then I have troubles installing FreeBSD.

If you do not care, the luanatics will put lua also in your soup.
 
shell to FreeBSD is like PowerShell to Windows. That thinBasic thing is red flag. OP said porting. Python, Lua, TCL, etc are fine. but OP needs to learn sh.
Handbook --> Porter's Handbook --> I need to learn sh! --> Learning sh --> I need to learn basic tools (regex, sed, grep, etc) --> Learning them --> back to learning sh --> back to Porter's Handbook.
 
Let's face it. There is a grain of truth in the OP's statements. The Shell Scripting Language is merely a catastrophe. It is the defacto substandard of coding and flawed beyond belief. We all use it with more or less success, but do we really like it?

I like JavaScript. When in doubt about any JS coding problem, I get in no time an answer to my question in any search engine. When in doubt about SH coding I get tons of non-answers for non-problems in BASH - eventually, somehow I find a solution, however it is almost never an easy going.

For example SH doesn't even care about operator precedence. I am almost sure, that the people who invented SH never heard about commutative and non-commutative operations, did they?
 
Sh is perfectly fine for small things, complex things can easily come close to be un-maintainable (and unreliable if not done with extra care), see the ports system. If we have managed already to get proper OCaml support on FreeBSD I would recommend it: easy to learn, rigorously documented, sanely developed, super fast, hand-way security, very flexible, and can also run as interpreted language (making it easy to convert to a compiled version if necessary).

#!/usr/bin/env ocamlrun
 

Haha!, a little sad you had to explicitly tell google to ignore 'jquery'?! That is cheating but does prove my point ;).

(In all honesty, with C++ I also have to add "-boost" to my queries too. This is one of the reasons why I recommended Awk because it is not extensible. No silly frameworks)

your favorite language C++ isn’t even mentioned on the first page
Can't tell if trolling or if you would consider a compiled language for shell scripting? Either way I would be horrified if "add event handler" returns a C++ result. That is a "web page" thing.

Edit: For me my 5th result was a C++ solution (emscripten): https://emscripten.org/docs/api_reference/html5.h.html
I guess that is because WebAssembly is becoming more popular than Javascript for web applications.

Either way. To check if something exists at a specified path in sh:
Code:
if [ -e "/some/path" ]; then
  echo "yay"
fi

I am fairly convinced that it would be less elegant or portable in Javascript (node.js or otherwise). It isn't easier in C or C++ so this kind of demonstrates why shell scripts are still in wide use.

But yes, I hadn't mentioned C++ in this thread yet but if you move on from scripting, then I highly recommend C++. If anything it is part of the base install, unlike Java or VisualBasic.Net (or its clones like Microsoft #cSharp)
 
If anything it is part of the base install, unlike Java or VisualBasic.Net (or its clones like Microsoft #cSharp)
Going off-topic (again first shell/regex!), but if you're going to develop on .Net platform, it's better to stick to C#. On Java, beside arguments on JSP and JVM, I have a feeling that it going completely replaced by PWA. Not now of course, but it's coming. Investment on Java for newcomers!? I don't do that.

On boost:
with C++ I also have to add "-boost" to my queries too
Are you categorically reject using boost or that was just an search example? I don't use boost, I'm just curious.
 
if you're going to develop on .Net platform, it's better to stick to C#
CSharp and VB.NET is basically the same thing (literally, the compilers share the same codebase). The name C# was a marketing ploy by Microsoft (similar to JavaScript) to cash in on the success of C++ and make casual developers feel part of the club. Perhaps consider C++/clr:safe instead. It is a .NET compiler which integrates better with professional middleware (i.e most actual software is written in native C or C++). It also provides a better upgrade path to C++/cx when Microsoft drops .NET entirely.

Are you categorically reject using boost or that was just an search example? I don't use boost, I'm just curious.
Yep, Boost rots too much. Software lifespan is more important to me than gimmicks.
 
  • Like
Reactions: a6h
I was agree that shell script is horrible.
And I read a very good tutorial that explain «sh» as a concept toolbox and an extention of other concept (file/folder, rwx rights, ...)
I was like every one, my shell script never had function and I wrote a lot of «if» statement.
But now, after learning the principle behind shell, I use a lot of function and «if» are very rare on my script.
Unfortunately, I lost the tutorial link, but maybe someone can find it or an another that explain shell in the same mindeset of it was designed.
After that shell is not so horrible, it can be maintained easily but there is still a limit, if you shell grow up, write C tools.

I forgot to mention the return with error code and the flags...
 
If the project is _really_ small you could use shell. However, if you want to extend it later or handle it in a professional way, stay away from shell. For systems related stuff I would also discourage you from using javascript, my suggestions: python if you are fine with a non-compiled environment (which has definitely its advantages) and if you don't need super-performance - for many projects python is ideal: very few lines of code compared to the same solution in other languages because the python universe offers tons of great libraries - python is a serious programming language/environment so you have lots of handy tools for debugging, logging, testing etc. If you want to use a compiled language which has definitely advantages over python in some situations (e.g. performance), go with golang. If you need the last bit of performance, you don't mind to write quite a few more lines of code but also want state of the art memory safety, go with rust.
 
Let's face it. There is a grain of truth in the OP's statements. The Shell Scripting Language is merely a catastrophe. It is the defacto substandard of coding and flawed beyond belief. We all use it with more or less success, but do we really like it?

I like JavaScript. When in doubt about any JS coding problem, I get in no time an answer to my question in any search engine. When in doubt about SH coding I get tons of non-answers for non-problems in BASH - eventually, somehow I find a solution, however it is almost never an easy going.

For example SH doesn't even care about operator precedence. I am almost sure, that the people who invented SH never heard about commutative and non-commutative operations, did they?
I must revisit my advocate for the traditional RC init of FreeBSD when I actually read one of them: ldconfig. I found like I'm lost in a forest. They used many variables like ldconfig_local_dirs, ldconfig_paths,... but no way I saw they defined these variable. I wanted to modify it to work with my FreeBSD distro where I replaced the FreeBSD Ports system with Ravenports, pkgng with ravensw (doing so my /usr/local is not available at all, as raven uses /raven, not /usr/local). Finally I have to give up because I have no idea how to patch it to work with my configuration.
 
I gave up on using JS as a system scripting language when I realize the engine I'm porting has their own extensions to the language and because of these extensions, their JS code all reported as have errors on major code editors and JS IDEs. I can't get the code completion to work with it, too. So I abandoned the idea of writing all of my scripts in JS completely.
 
where I replaced the FreeBSD Ports system with Ravenports, pkgng with ravensw (doing so my /usr/local is not available at all, as raven uses /raven, not /usr/local).

I do something similar (I have /usr/local, /usr/site, /usr/pkgsrc). I was a big fan of the Solaris 10 way of doing things basically ;)

Just remember you can set LD_LIBRARY_PATH. I.e

Code:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/site/lib:/usr/pkgsrc/lib

Just set it in your ~/.profile
 
I was agree that shell script is horrible...I was like every one, my shell script never had function and I wrote a lot of «if» statement.
But now, after learning the principle behind shell, I use a lot of function and «if» are very rare on my script...

You should look into awk(1) if you dislike writing if-then logic. Awk's expressiveness and power really shine when you use patterns even though they're considered "advanced" by some. Take the somewhat contrived example of counting shell usage by user, and paying special attention to root's shell:

Code:
#!/usr/bin/awk -f

# Set the field separator to ":". Default is whitespace
BEGIN { FS=":" }

# Skip comment lines
/^#/ { next }

# Capture root's shell
$1 ~ /root/ { rootShell=$7 }

# Keep shell usage counts
$7 != "" { shells[$7]++ }
$7 == "" { shells["No shell"]++ }

# Print results
END {
    print "Root's shell is", rootShell;
    for( i in shells ) {
            print i, shells[i];
    }
}

Sample run:
Code:
% ./shells.awk /etc/passwd
Root's shell is /bin/csh
No shell 1
/usr/local/libexec/uucp/uucico 1
/bin/csh 2
/usr/sbin/nologin 33

I find writing programs as a list of conditon -> action pairs fun and compelling.
 
shell to FreeBSD is like PowerShell to Windows. That thinBasic thing is red flag. OP said porting. Python, Lua, TCL, etc are fine. but OP needs to learn sh.
Handbook --> Porter's Handbook --> I need to learn sh! --> Learning sh --> I need to learn basic tools (regex, sed, grep, etc) --> Learning them --> back to learning sh --> back to Porter's Handbook.
Why you think Thinbasic is read flag? What's wrong with your reading? Thinbasic in Windows-only product. How the hell I could port it to Unix? I'm not have the skills needed to make a Unix clone of it too.
 
  • Like
Reactions: a6h
Sh is perfectly fine for small things, complex things can easily come close to be un-maintainable (and unreliable if not done with extra care), see the ports system. If we have managed already to get proper OCaml support on FreeBSD I would recommend it: easy to learn, rigorously documented, sanely developed, super fast, hand-way security, very flexible, and can also run as interpreted language (making it easy to convert to a compiled version if necessary).

#!/usr/bin/env ocamlrun
Then now you stopped advocating for Ada but switched to OCaml? ;) BTW, thank you :)
 
I do something similar (I have /usr/local, /usr/site, /usr/pkgsrc). I was a big fan of the Solaris 10 way of doing things basically ;)

Just remember you can set LD_LIBRARY_PATH. I.e

Code:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/site/lib:/usr/pkgsrc/lib

Just set it in your ~/.profile
I know this. But this is hacky. Shouldn't be used for a proper distro like what I used to be trying to do. The proper way is the ldconfig service that you saw printed a bunch of lines when the system startup. But as you said you used old FreeBSD versions, I think you would not know it since it's a later addition of newer versions (at least I think so).

If you are good at shell, may be you could have a look at /etc/rc.d/ldconfig (if it exists on your system at all) and let me know how could I add an alternative location for /usr/local/libdata/ldconfig since my distro doesn't have /usr/local? Thank you :)

p/s: I'm lost when reading that script. I'm not even found /usr/local/libdata/ldconfig on it.
 
Why you think Thinbasic is read flag? What's wrong with your reading? Thinbasic in Windows-only product. How the hell I could port it to Unix? I'm not have the skills needed to make a Unix clone of it too.
I think the reality is if you're going to stick with FreeBSD you'll need to learn shell scripting. It will just make things easier. It will also allow you to understand the thousands of scripts out there to help with day to day activities. It's not a waste of time, IMO.

I am not sure where this Thinbasic comes into the discussion. I know you raised it in your original message but I didn't/don't understand its relevance to your issue.

Is it not a langauge like cbasic, truebasic, realbasic, visualbasic etc? It's not a scripting language, per se, is it?
 
I think the reality is if you're going to stick with FreeBSD you'll need to learn shell scripting. It will just make things easier. It will also allow you to understand the thousands of scripts out there to help with day to day activities. It's not a waste of time, IMO.

I am not sure where this Thinbasic comes into the discussion. I know you raised it in your original message but I didn't/don't understand its relevance to your issue.

Is it not a langauge like cbasic, truebasic, realbasic, visualbasic etc? It's not a scripting language, per se, is it?
Offtopic on: Thinbasic is a scripting language, not compiled language like other variants of basic.

BTW, I don't say I wanted to avoid shell at all. I know it's impossible. But I only want to use it the least possible. I have problems reading and understanding shell scripts.
 
Back
Top