Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuichiueda committed Jan 5, 2024
2 parents 472da6f + efc065e commit 0583842
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 41 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: macos-latest

on:
push:
branches: [ main, sd/* ]
paths: ['src/**', 'test/**', '!README.md' ]
pull_request:
branches: [ main ]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: macos-latest

steps:
- uses: actions/checkout@v3
- name: Bash tests
run: bash -xv ./test/test.bash
16 changes: 0 additions & 16 deletions .github/workflows/test.yml

This file was deleted.

21 changes: 21 additions & 0 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: ubuntu-latest

on:
push:
branches: [ main, sd/* ]
paths: ['src/**', 'test/**', '!README.md' ]
pull_request:
branches: [ main ]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Bash tests
run: bash -xv ./test/test.bash
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sush"
version = "2024.7.2"
version = "2024.8.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
# Rusty Bash (a.k.a. sushi 🍣 shell)

<<<<<<< HEAD
=======
[![ubuntu-latest](https://github.com/shellgei/rusty_bash/actions/workflows/ubuntu.yml/badge.svg)](https://github.com/shellgei/rusty_bash/actions/workflows/ubuntu.yml)
[![macos-latest](https://github.com/shellgei/rusty_bash/actions/workflows/macos.yml/badge.svg)](https://github.com/shellgei/rusty_bash/actions/workflows/macos.yml)
![](https://img.shields.io/github/license/shellgei/rusty_bash)

>>>>>>> sd/202407_5
**IMPORTANT: the main branch is switched to the shell develped for articles on [SoftwareDesign](https://gihyo.jp/magazine/SD).**
(今までのメインブランチは、連載のものに比べて散らかりすぎなので、連載のものをmainに切り替えました。)

* [old main branch](https://github.com/shellgei/rusty_bash/tree/old_main)

<<<<<<< HEAD
[![Rust](https://github.com/shellgei/rusty_bash/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/shellgei/rusty_bash/actions/workflows/test.yml)
![](https://img.shields.io/github/license/shellgei/rusty_bash)
=======
>>>>>>> sd/202407_5
## What's this?

Expand Down
3 changes: 2 additions & 1 deletion src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl ShellCore {
if is_interactive() {
core.flags += "i";
core.tty_fd = fcntl::fcntl(2, fcntl::F_DUPFD_CLOEXEC(255))
.expect("Can't allocate fd for tty FD");
.expect("sush(fatal): Can't allocate fd for tty FD");
}

core
Expand Down Expand Up @@ -210,3 +210,4 @@ impl ShellCore {
res
}
}

2 changes: 1 addition & 1 deletion src/elements/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Pipeline {
for (i, p) in self.pipes.iter_mut().enumerate() {
p.set(prev, pgid);
pids.push(self.commands[i].exec(core, p));
if i == 0 { // 最初のexecが終わったら、pgidにコマンドのPIDを記録
if i == 0 && pgid.as_raw() == 0 { // 最初のexecが終わったら、pgidにコマンドのPIDを記録
pgid = pids[0].expect("SUSHI INTERNAL ERROR (unforked in pipeline)");
}
prev = p.recv;
Expand Down
44 changes: 22 additions & 22 deletions test/test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ res=$($com <<< '(echo hoge; false)')
res=$($com <<< 'cd / ; (cd /etc); pwd')
[ "$res" = / ] || err $LINENO

res=$($com <<< 'cd / ; { cd /etc ; } ; pwd')
[ "$res" = /etc ] || err $LINENO
res=$($com <<< 'cd ; { cd / ; } ; pwd')
[ "$res" = / ] || err $LINENO

res=$($com <<< '( )')
[ "$?" = 2 ] || err $LINENO
Expand Down Expand Up @@ -120,27 +120,27 @@ res=$($com <<< 'eeeeeecho hoge')

### PIPELINE ###

res=$($com <<< 'seq 3 | tac | head -n 1')
[ "$res" = "3" ] || err $LINENO
res=$($com <<< 'seq 10 | rev | tail -n 1')
[ "$res" = "01" ] || err $LINENO

res=$($com <<< 'seq 3 |
tac | head -n 1')
[ "$res" = "3" ] || err $LINENO
res=$($com <<< 'seq 10 |
rev | tail -n 1')
[ "$res" = "01" ] || err $LINENO

res=$($com <<< 'seq 3 |
res=$($com <<< 'seq 10 |
tac | head -n 1')
[ "$res" = "3" ] || err $LINENO
rev | tail -n 1')
[ "$res" = "01" ] || err $LINENO

res=$($com <<< 'seq 3 | #コメントだよ
res=$($com <<< 'seq 10 | #コメントだよ
#コメントだよ
#こめんとだよ
tac | head -n 1')
[ "$res" = "3" ] || err $LINENO
rev | tail -n 1')
[ "$res" = "01" ] || err $LINENO

res=$($com <<< 'seq 3 | | head -n 1')
res=$($com <<< 'seq 10 | | head -n 1')
[ "$?" = "2" ] || err $LINENO

### COMMENT ###
Expand Down Expand Up @@ -189,7 +189,7 @@ res=$($com <<< 'echo hoge |\
& rev')
[ "$res" = "egoh" ] || err $LINENO

res=$($com <<< ' (seq 3; seq 3) | grep 3 | wc -l')
res=$($com <<< ' (seq 3; seq 3) | grep 3 | wc -l | tr -dc 0-9')
[ "$res" = "2" ] || err $LINENO

res=$($com <<< 'ls | | rev')
Expand Down Expand Up @@ -218,7 +218,7 @@ res=$($com <<< '
cd - > /tmp/rusty_bash2
cat /tmp/rusty_bash1
cat /tmp/rusty_bash2
pwd')
pwd' | sed [email protected]@@)
[ "$res" = "/etc
/tmp
/tmp" ] || err $LINENO
Expand All @@ -230,7 +230,7 @@ res=$($com <<< '
{ cd - ; } > /tmp/rusty_bash2
cat /tmp/rusty_bash1
cat /tmp/rusty_bash2
pwd')
pwd' | sed [email protected]@@)
[ "$res" = "/etc
/tmp
a
Expand All @@ -243,19 +243,19 @@ res=$($com <<< '
ls /aaaa 2> /tmp/rusty_bash
ls /bbbb 2>> /tmp/rusty_bash
cat /tmp/rusty_bash | grep ls | wc -l
')
' | tr -dc 0-9)
[ "$res" = "2" ] || err $LINENO

# &>

res=$($com <<< 'ls /etc/passwd aaaa &> /tmp/rusty_bash; cat /tmp/rusty_bash | wc -l')
res=$($com <<< 'ls /etc/passwd aaaa &> /tmp/rusty_bash; cat /tmp/rusty_bash | wc -l | tr -dc 0-9')
[ "$res" == "2" ] || err $LINENO

# &> for non-fork redirects

res=$($com <<< '
{ ls /etc/passwd aaaa ; } &> /tmp/rusty_bash
cat /tmp/rusty_bash | wc -l')
cat /tmp/rusty_bash | wc -l | tr -dc 0-9')
[ "$res" == "2" ] || err $LINENO

res=$(LANG=C $com <<< '
Expand All @@ -265,7 +265,7 @@ res=$(LANG=C $com <<< '
{ ls /etc/passwd ; }
{ ls aaaa ; } 2> /tmp/rusty_bash2
cat /tmp/rusty_bash2 | wc -l
')
' | tr -d [:blank:])
[ "$res" == "2
/etc/passwd
1" ] || err $LINENO
Expand All @@ -277,7 +277,7 @@ res=$($com <<< '
{ cd - ; } &> /tmp/rusty_bash2
cat /tmp/rusty_bash1
cat /tmp/rusty_bash2
pwd')
pwd' | sed [email protected]@@)
[ "$res" = "/etc
/tmp
a
Expand Down

0 comments on commit 0583842

Please sign in to comment.