COSH는 연결 명령 줄 쉘입니다.
ls
, ps
, stat
등과 같은 기본 쉘 작업은 텍스트 스트림을 반환하는 실행 파일에 의존하는 대신 일류 값을 반환하는 함수로 구현됩니다. 이것은 결과를 더 간단하게 만듭니다.
문자열과 일치하는 파일 경로를 찾고 해당 파일을 데이터에 대해 검색하십시오.
쉿 | 찾다 . -iname '*test*'-print0 | XARGS -0 GREP 데이터 |
곤봉 | LSR; [테스트 m] grep; [f <; [데이터 m] grep] 맵 |
500m 이상의 메모리를 사용하여 모든 프로세스를 찾으십시오.
쉿 | ps-no-headers aux | awk '$ 6> 500000' |
곤봉 | 추신; [mem get; 1000100 *; 500 *; >] grep |
소량의 다목적 프리미티브 세트는 일반적인 쉘과 비교할 때 (예 : cut(1)
의 다양한 플래그 참조)과 비교할 때 기억이 적을 필요가 있음을 의미하지만, 일부 명령은 결과적으로 더 길 수 있습니다.
CSV 파일의 각 행에서 두 번째 및 세 번째 열을 가져옵니다.
쉿 | 컷 -d, -f2,3 테스트 -데이터/CSV |
곤봉 | 테스트 데이터/CSV F <; [chomp; , 나뉘다; (1 2) 맵을 얻습니다 |
수정 시간별로 파일을 정렬합니다.
쉿 | ls -tr |
곤봉 | ls; [[통계; mtime get] 2 적용; <=>] sortp |
산술 연산자 및 XML/JSON/YAML/CSV 인코딩/디코딩 기능은보다 완전한 기능을 갖춘 프로그래밍 언어 또는 타사 실행 파일을 사용하는 데 필요한 횟수를 줄입니다.
파일의 부동 소수점 번호 증분 :
쉿 | sed 's/$/+10/'nums | 기원전 |
곤봉 | nums f <; [chomp; 10 +]지도 |
JSON 파일의 "ZXCV"배열 멤버에서 첫 번째 값을 얻으십시오.
쉿 | JQ .ZXCV [0] Test-Data/JSON2 |
곤봉 | 테스트-데이터/json2 f <; JSON에서; ZXCV GET; 0 |
또한 외부 실행 가능 호출과 통합되어야합니다.
인증서 데이터 :
세게 때리다 | `찾기. -iname '*.pem'; do openssl x509 -in $ i -text -noout; 완료 |
곤봉 | LSR; [pem $ m] grep; [{OpenSSL x509 -in {} -text -noout}] 맵; |
자세한 내용은 전체 문서를 참조하십시오.
이것은 Linux (Debian 12)에서 테스트되었지만 Rust를 구축 할 수있는 Linux/MacOS/BSD 시스템에서 작동해야합니다.
make
make test
sudo make install
핵심 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$
일련의 도메인 이름에 대한 핑 타임을 동시에 찾으십시오.
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$
선적 서류 비치
라이센스를 참조하십시오.