qsh

command module
v0.0.0-...-6e7b214 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2023 License: BSD-3-Clause Imports: 11 Imported by: 0

README

qsh

q shell

INSTALLATION

$ go get github.com/lufia/qsh

Language

Comment
# comment
Variables

Simple declaration.

a=1     # scalar; same as a=(1)
a=(1 2) # array

echo $a
# Output:
# 1 2

if variable name all are capital letter, it handles as environment variables.

RESULT_CODE=1
bash -c 'echo $RESULT_CODE'
# Output: 1

Indirect reference

arch=lib_amd64
lib_amd64=lib64
lib_x86=lib

echo $$arch
# Output:
# lib64
If statement
if { true } {
	echo ok
}
# Output:
# ok
For statement
for i in 1 2 3 {
	echo $i
}
# Output:
# 1
# 2
# 3
Modules

first, write your code in Go.

package main

var SampleModule = map[string]string{
	"hello": "Hello",
}

func Hello(args []string) ([]string, error) {
	a := make([]string, 0, len(args)+1)
	a = append(a, "hello")
	return append(a, args...), nil
}

build it as plugin.

go build -buildmode=plugin sample.go

then load with load stamtement.

load sample # plugin filepath without .so
echo ${hello a ${hello b}}
# Output: hello a hello b
Expression
true && echo true

false || echo false
Redirection
# output
echo hello >out

# append
echo hello >>out

# input
echo hello <in

# pipe
echo hello | wc

TODO

  • Basic
    • comments
    • command execution
    • background execution
    • inline execution
    • glob
  • Variable
    • assign
    • indexing
    • concat
    • environment
  • Redirection
    • read
    • write
    • append
    • error
    • pipe
    • dup
  • Statements
    • if
    • if-else
    • for
    • switch
    • load
  • Expression
    • &&
    • ||

Advent calendar

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL