[Gambas-user] Gambas Linux Shell - GSH

Brian G brian at westwoodsvcs.com
Thu Jan 13 23:07:13 CET 2022


With Gambas Script gsh it is possible to use brace and file, cli Result  expansion in your scripts.
https://github.com/justlostintime/GambasShell/wiki

It has some useful features as a shell for day to day functions, as well as
providing an immersive Gambas environment to work from.
   
Used for iteration:
   for each i as integer in $"01..10"
      print i;;
   next
   >1 2 3 4 5 6 7 8 9 10
 
Used For iteration as text:
   for each i as string in $"01..10"
      print i;;
   next
   >01 02 03 04 05 06 07 08 09 10

Used for iteration with text and name generation
   print $"a{01..10}".join(" ")
   >a01 a02 a03 a04 a05 a06 a07 a08 a09 a10

Generate some pre-named file:   
   touch $"a{01..10}"
   ls a*
   >a01 a02 a03 a04 a05 a06 a07 a08 a09 a10
   
Generate even more files:
   touch $"a{01..10}.py"
   touch $"a{01..10}.bat"
   touch $"a{01..10}.bin"
   ls
   > a01      a01.bin  a02 a02.bin  a03 a03.bin  a04 a04.bin  a05
    a05.bin  a06      a06.bin  a07      a07.bin  a08      a08.bin  a09  
    a09.bin  a10      a10.bin a01.bat  a01.py   a02.bat  a02.py   a03.bat  
    a03.py   a04.bat  a04.py   a05.bat  a05.py   a06.bat  a06.py   a07.bat  a07.py 
    a08.bat  a08.py   a09.bat  a09.py   a10.bat  a10.py   

Print the list of selected files:
   echo $"*.{bat,py}"
   >a01.bat a02.bat a03.bat a04.bat a05.bat a06.bat a07.bat a08.bat a09.bat a10.bat a01.py a02.py a03.py a04.py a05.py a06.py a07.py a08.py a09.py a10.py


Expand the result from the cli call which also contains a file expansion:
  for each s as string in $`ls -l $"*.{bat,py}"`
     print s
  next




"Failure is the key to success; 
 each mistake teaches us something"  .. Morihei Ueshiba
Brian G

----- On Jan 2, 2022, at 1:09 PM, Brian G brian at westwoodsvcs.com wrote:

> Playground help is also supported in the shell
> 
>> help loop
> Please select Choice using number
> 0) Event Loop
> 1) LOOP
> 2) Loop Control Structures
> 3) loops_break
> 0
> 
> NAME
> event loop
> The event loop is an internal function of the Gambas interpreter that waits for
> system events and dispatch them as they arrive.
> These system events can come from the user interface, from a child process, from
> a timer... They are usually followed by a normal Gambas.
> 
> 
> See also
>    * Event_Loop
> 
>> help loop
> Please select Choice using number
> 0) Event Loop
> 1) LOOP
> 2) Loop Control Structures
> 3) loops_break
> 2
> NAME
> Loop Control Structures
> BREAK             Leaves a loop immediately.
> CONTINUE          Jumps to the next occurence of a loop.
> DO ... LOOP       Infinite loop.
> FOR ... NEXT      Counter loop.
> FOR_EACH ... NEXT Enumeration loop.
> REPEAT ... UNTIL  Loop with an exit test at the end.
> WHILE ... WEND    Loop with an exit test at the beginning.
> 
>>
> 
> 
>> playground
> Listing Playground Examples
> Process Response
>  1) 100 doors                                                   28) Exceptions
>  .....
>  2) ABC Problem                                                 29) Execute a
>  system command     .....
> 
> ........ List Everything in playground ......
> 
> Enter the Number of the example you would like to work with 0 or Q to quit? > 2
> 
> Function loaded it may be executed by entering : abc_problem
> or edited by entering : edit abc_problem
>> List abc_problem
> Public Sub abc_problem()
> Dim sCheck As String[] = ["A", "BARK", "BOOK", "TREAT", "COMMON", "SQUAD",
> "CONFUSE"]
> Dim sBlock As String[] = ["BO", "XK", "DQ", "CP", "NA", "GT", "RE", "TG", "QD",
> "FS", "JW", "HU", "VI", "AN", "OB", "ER", "FS", "LY", "PC", "ZM"]
> Dim sList As New String[]
> Dim siCount, siLoop As Short
> Dim sTemp, sAnswer As String
> 
> For Each sTemp In sCheck
>  sAnswer = ""
>  sList = sBlock.Copy()
>  For siCount = 1 To Len(sTemp)
>    For siLoop = 0 To sList.Max
>      If InStr(sList[siLoop], Mid(sTemp, siCount, 1)) Then
>        sList.Extract(siLoop, 1)
>        sAnswer &= Mid(sTemp, siCount, 1)
>        Break
>      Endif
>    Next
>  Next
> 
> If sAnswer = sTemp Then
>   Print sTemp & " - True"
> Else
>   Print sTemp & " - False"
> End If
> Next
> 
> End
> 
>> abc_problem
> A - True
> BARK - True
> BOOK - False
> TREAT - True
> COMMON - False
> SQUAD - True
> CONFUSE - True
> 
>> edit abc_problem
> 
>>
> 
> 
> 
> 
> "Failure is the key to success;
> each mistake teaches us something"  .. Morihei Ueshiba
> Brian G
> 
> ----- On Dec 30, 2021, at 8:34 AM, Brian G brian at westwoodsvcs.com wrote:
> 
>> In the shell it is possible to do things such as
>> 
>> if `ls -l | tr [a-z] [A-Z] > $a` = 0 then
>>    print $a
>> else
>>    echo the command failed
>> endif
>> 
>> from the command line or in a script
>> 
>> or shortcuts such as
>> 
>> tcb Thisfile                       ' Copy this file to the clipboard
>> 
>> !fcb > "thisfile"                  ' copy clipboard to a file
>> !fcb | tc [a-z] [A-Z] | less       ' pass clipboard contents to a process
>> !fcb > $a                          ' clipboard To a global variable for use in a
>> script
>> fromclipboard                      ' just print clipboard to the terminal
>> 
>> browse                             ' Opens a filebrowser in the current
>> directory with no wait
>> browse /                           ' Opens the file  browser at the root
>> directory
>> 
>> google "New Socks"                 ' Opens the default internet browser search
>> page
>> 
>> for each s as string in $"a{b..f}/filename" ' auto file name expansion and
>> enumeration
>>    touch {s}
>> next
>> 
>> 
>> "Failure is the key to success;
>> each mistake teaches us something"  .. Morihei Ueshiba
>> Brian G
>> 
>> ----- On Dec 29, 2021, at 6:11 PM, Martin Belmonte mbelmonte at belmotek.net wrote:
>> 
>>> El 29/12/21 a las 23:14, Brian G escribió:
>>>> Hi Everyone,
>>>> Over the past couple of years I have developed a Gambas interactive shell, It is
>>>> finally at a point where I have been using as my daily driver at work and home.
>>>> In my environment it replaces bash for the most part.
>>>> 
>>>> It can be found here [ https://github.com/justlostintime/GambasShell/wiki |
>>>> https://github.com/justlostintime/GambasShell/wiki ]
>>>> 
>>>> If anyone finds it interesting I would love some feedback.
>>> Great, congratulations. I see there is a pdf manual and quite a lot of
>>> documentation, good point.
>>> I am now trying to make a CAD with gambas, so I don't know if I will be
>>> able to test but you never know.
>>> Martín.
>>> 
>>> 
>>> 
>>> 
>>> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>> 
>> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
> 
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----


More information about the User mailing list