COSH เป็นเชลล์บรรทัดคำสั่ง concatenative
การดำเนินการเชลล์พื้นฐานเช่น ls
, ps
, stat
และอื่น ๆ จะถูกนำมาใช้เป็นฟังก์ชั่นที่ส่งคืนค่าคลาสเฟิร์สคลาสซึ่งตรงข้ามกับการใช้งานที่ส่งกลับข้อความ สิ่งนี้ทำให้การทำงานกับผลลัพธ์ง่ายขึ้น:
ค้นหาพา ธ ไฟล์ที่ตรงกับสตริงและค้นหาไฟล์เหล่านั้นสำหรับข้อมูล
SH | หา . -iname '*test*' -print0 | ข้อมูล XARGS -0 GREP |
ความโกลาหล | LSR; [ทดสอบ M] GREP; [f <; [data m] grep] แผนที่ |
ค้นหากระบวนการทั้งหมดโดยใช้หน่วยความจำมากกว่า 500 ม.:
SH | PS-ไม่มีหัวหน้า Aux | awk '$ 6> 500000' |
ความโกลาหล | ป.ล. ; [mem get; 1,000 1,000 *; 500 *; >] grep |
ชุดดั้งเดิมที่หลากหลายหมายความว่าจำเป็นต้องจดจำน้อยลงเมื่อเปรียบเทียบกับเปลือกหอยทั่วไป (ดูเช่นธงต่าง ๆ สำหรับ cut(1)
) แม้ว่าคำสั่งบางอย่างอาจยาวขึ้นตาม:
รับคอลัมน์ที่สองและสามจากแต่ละแถวของไฟล์ CSV:
SH | CUT -D, -F2,3 TEST -DATA/CSV |
ความโกลาหล | ทดสอบข้อมูล/CSV F <; [Chomp; , แยก; (1 2) รับ] แผนที่ |
เรียงลำดับไฟล์ตามเวลาแก้ไข:
SH | ls -tr |
ความคึกคัก | ls; [[Stat; mtime get] 2 ใช้; <=>] sortp |
ตัวดำเนินการทางคณิตศาสตร์และ XML/JSON/YAML/CSV ฟังก์ชั่นการเข้ารหัส/ถอดรหัสลดจำนวนครั้งที่จำเป็นต้องใช้ภาษาการเขียนโปรแกรมที่มีคุณสมบัติครบถ้วนมากขึ้นหรือการดำเนินการของบุคคลที่สาม:
เพิ่มจำนวนจุดลอยตัวในไฟล์:
SH | sed 's/$/+10/' nums | BC |
ความโกลาหล | nums f <; [Chomp; 10 +] แผนที่ |
รับค่าแรกจากสมาชิกอาร์เรย์ "ZXCV" ของไฟล์ JSON:
SH | jq .zxcv [0] test-data/json2 |
ความโกลาหล | ทดสอบข้อมูล/json2 f <; จาก-json; ZXCV ได้รับ; 0 รับ |
นอกจากนี้ยังรวมเข้ากับการเรียกใช้งานภายนอกที่จำเป็นซึ่งจำเป็น:
ข้อมูลใบรับรองพิมพ์:
ทุบตี | สำหรับฉันใน `ค้นหา -iname '*.pem'`; ทำ openssl x509 -in $ i -text -noout; เสร็จแล้ว |
ความโกลาหล | LSR; [PEM $ M] GREP; [{openssl x509 -in {} -text -noout}] แผนที่; |
ดูเอกสารฉบับเต็มสำหรับรายละเอียดเพิ่มเติม
สิ่งนี้ได้รับการทดสอบใน Linux (Debian 12) แต่ควรทำงานกับระบบ Linux/MacOS/BSD ใด ๆ ที่สามารถสร้างสนิมได้
make
make test
sudo make install
นอกเหนือจาก Core cosh
ที่เรียกใช้งานแล้วสิ่งนี้จะติดตั้งไลบรารีที่รวบรวมไว้ของฟังก์ชั่นหลัก ( rt.chc
)
user@host:/$ cosh
/$ hello println;
hello
แต่ละตัวอย่างเริ่มต้นจากไดเรกทอรีโคลนที่เก็บ
รายการไฟล์ในไดเรกทอรีที่ระบุ:
cosh$ test-data ls
v[gen (
0: test-data/cert.der
1: test-data/json-bigint
2: test-data/json2
3: test-data/json1
4: test-data/readfile
5: test-data/yaml1.yml
6: test-data/test.ch
7: test-data/csv
8: test-data/split
9: test-data/readlines
)]
cosh$
เรียงลำดับไฟล์ตามตัวอักษรในไดเรกทอรีที่ระบุ:
cosh$ test-data ls; sort
(
0: test-data/cert.der
1: test-data/csv
2: test-data/json-bigint
3: test-data/json1
4: test-data/json2
5: test-data/readfile
6: test-data/readlines
7: test-data/split
8: test-data/test.ch
9: test-data/yaml1.yml
)
cosh$
คำสั่งภายนอกสามารถเรียกใช้โดยนำหน้าคำสั่งด้วยพื้นที่:
cosh$ vim test-data/csv
...
อ่านไฟล์ลงในหน่วยความจำ:
cosh$ test-data/csv f<;
v[gen (
0: "1,2,3,4n"
1: "5,6,7,8n"
2: "9,10,11,12n"
)]
cosh$
สำหรับแต่ละบรรทัดของไฟล์ CSV ให้ลบ Newline และแยกออกเป็นเครื่องหมายจุลภาค:
cosh$ test-data/csv f<; [chomp; , split] map;
v[gen (
0: (
0: 1
1: 2
2: 3
3: 4
)
1: (
0: 5
1: 6
2: 7
3: 8
)
2: (
0: 9
1: 10
2: 11
3: 12
)
)]
cosh$
อ่านไฟล์ JSON ลงในหน่วยความจำ:
cosh$ test-data/json2 f<; from-json;
h(
"asdf": 1
"qwer": 2
"tyui": h(
"asdf": 5
)
"zxcv": (
0: 3
1: 4
)
)
cosh$
รับชื่อฟิลด์จากไฟล์ JSON และพิมพ์ลงในเอาต์พุตมาตรฐาน:
cosh$ test-data/json2 f<; from-json; keys; println for;
asdf
qwer
tyui
zxcv
cosh$
ค้นหาชื่อฟิลด์ที่ตรงกับ regex ที่กำหนด:
cosh$ test-data/json2 f<; from-json; keys; [.{4} m] grep;
v[gen (
0: asdf
1: qwer
2: tyui
3: zxcv
)]
cosh$
cosh$ test-data/json2 f<; from-json; keys; [a..f m] grep;
v[gen (
0: asdf
)]
cosh$
กำหนดและใช้ฟังก์ชั่นใหม่:
cosh$ : add-5 5 +; ,,
cosh$ (1 2 3) add-5 map;
(
0: 6
1: 7
2: 8
)
cosh$
จับค่าโดยใช้ regex:
cosh$ test-data ls;
v[gen (
0: test-data/json-bigint
1: test-data/json2
2: test-data/json1
3: test-data/readfile
4: test-data/csv
5: test-data/split
)]
cosh$ test-data ls; ["/.*" c; shift] map;
v[gen (
0: /json-bigint
1: /json2
2: /json1
3: /readfile
4: /csv
5: /split
)]
cosh$
พิมพ์เวลาปรับเปลี่ยนเส้นทางในรูปแบบเฉพาะ:
cosh$ test-data stat; mtime get; from-epoch; %F strftime;
2023-01-20
cosh$
ค้นหา Ping Times สำหรับชุดชื่อโดเมนในแบบขนาน:
cosh$ (sourcehut.org github.com gitlab.com) [dup; A dig; answer.0.sdata.address get; 1 pingn; 0 get; 2 mlist] pmap;
v[channel-gen (
0: (
0: gitlab.com
1: h(
"icmp_seq": 1
"ttl": 58
"time_ms": 11.6
)
)
1: (
0: github.com
1: h(
"icmp_seq": 1
"ttl": 115
"time_ms": 28.4
)
)
2: (
0: sourcehut.org
1: h(
"icmp_seq": 1
"ttl": 52
"time_ms": 346
)
)
)]
cosh$
รับจำนวนโฮสต์ทั้งหมดในชุดที่อยู่ IP:
cosh$ (1.0.0.0/24 2.0.0.0/14 3.0.0.0/8) [ip; ip.size] map; sum
17039616
cosh$
สร้างฐานข้อมูล SQLite ใหม่เพิ่มตารางลงในฐานข้อมูลและเพิ่มระเบียนลงในตาราง:
cosh$ mydb touch
cosh$ mydb sqlite db.conn; c var; c !
cosh$ c @; "create table test (id, num)" db.prep; () db.exec
()
cosh$ c @; "insert into test values (?, ?)" db.prep; (1 2) db.exec
()
cosh$ c @; "select * from test" db.prep; () db.exec
(
0: h(
"id": 1
"num": 2
)
)
cosh$
เอกสาร
ดูใบอนุญาต