ShellJs & bash
- Getting headaches trying to read a bash script?
- Nausea when trying to write a bash script?
- Annoyed when having to fix a bash script?
ShellJS
- Easy to follow code
- No more google-first variables
- Easier to understand
Advantages
- Works on windows
- Extendable with npm libraries, project libraries
- Parse JSON (and other formats)
- SE's can understand it
- Can monitor an async process
- Easier linting, unit testing
- Useable arrays
Disadvantages
- Npm install first, run after
- Significantly slower
- Daemon = 100% of a core
Side by side comparison
#!/usr/bin/env node
require ('shelljs/global');
var lsla = exec('ls -la', {silent:true});
chmod('644', '*.mp3');
if(lsla.code == 0) {
console.log("Success");
}
console.log(lsla.output);#!/usr/bin/env bash
lslaoutput=$(ls -la)
#chmod -R 644 *.mp3
lslacode=$?
if [ $lslacode -eq 0 ]; then
echo "Success"
fi
echo $lslaoutputSide by side comparison
#!/usr/bin/env node
require ('shelljs/global');
var list = prepare_list( process.argv[2], process.argv[3], process.argv[4] );
for (i = 0; i < list.length; i++) {
do_something(list[i]);
}#!/usr/bin/env bash
echo '' >> /tmp/list.txt
prepare_list "$1" "$2" "$3"
while read A B C D; do
do_something "$A" "$B" "$C" "$D"
done < /tmp/list.txt
rm -f /tmp/apps.txtSide by side comparison
Q&A
Thank you.
ShellJs - En
By cz
ShellJs - En
- 125