How to extend the bash shell?

I would like to add new functionality to the bash shell. I need to have a queue to execute.

What is an easy way to add new functionality to a bash shell that retains all native functions? I would like to process the command line and then let bash execute them. For users, this should be transparent.

Thanks Arman

EDIT

I just discovered prll.sourceforge.net, it does exactly what I need.

+3
source share
1 answer

This is easier than it sounds:

#!/bin/sh
yourfunctiona(){ ...; }
...
yourfunctionz(){ ...; }
. /path/to/file/with/more/functions

while read COMMANDS; do
  eval "$COMMANDS"
done

read -p, -t, , -... , tailbox

touch /tmp/mycmdline
Xdialog --tailbox /tmp/mycmdline 0 0 &
COMMANDS="echo "
while ([ "$COMMANDS" != "" ]); do
  COMMANDS=`Xdialog --stdout --inputbox "Text here" 0 0`
  eval "$COMMANDS"
done >>/tmp/mycmdline &

eval $COMMANDS

#this will need to be before the loope
NUMCORES=$(awk '/cpu cores/{sum += $4}END{print sum}' /proc/cpuinfo)

for i in {1..$NUMCORES};do
  if [ $i -eq $NUMCORES ] && #see comments below
  if [ -d /proc/$threadarray[$i] ]; then #this core already has a thread
#note: each process gets a directory named /proc/<its_pid> - hacky, but works
    continue
  else #this core is free
    $COMMAND &
    threadarray[$i]=$!
    break
fi
done

, . while, , ​​ (, )

:

wait $threadarray[$i]

:

 wait
#I ended up using this to keep my load from getting to high for too long

: , , case

, (, , , , , )

+2

Source: https://habr.com/ru/post/1767643/


All Articles