--- title: "Using knitractive with Bash" author: "Jeroen Janssens" date: "`r Sys.Date()`" output: github_document --- *View the corresponding [bash.Rmd file](https://raw.githubusercontent.com/jeroenjanssens/knitractive/master/vignettes/examples/bash.Rmd) to learn more about how this page was generated.* ```{r setup, include = FALSE} knitractive::start(name = "bash", command = rexpect::cmd_docker(image = "ubuntu:20.04"), prompt = rexpect::prompts$bash) ``` ```{bash, include=FALSE} PS1='$ ' apt-get update apt-get install -y curl cowsay alias cowsay='/usr/games/cowsay' ``` ## Set a variable ```{bash set_name} NAME=$(whoami) ``` ## Spread a pipeline over multiple lines ```{bash multiple} seq 100 | grep 3 | wc -l ``` ## Retrieve a value ```{bash get_name} cowsay "I am g${NAME}" ``` ## Command substitution ```{bash cran} echo "CRAN has $( curl -sL cran.r-project.org/web/packages/available_packages_by_date.html | grep "index.html" | wc -l ) packages" ``` ## Take a screenshot of `top` ```{bash run_top} top#! literal = FALSE ``` After two seconds we see the following screen: ```{bash start_top, highlight = FALSE, fullscreen = TRUE} Enter#! literal = FALSE, hold = 3 ``` Press **q** to exit `top`. ```{bash exit_top, include = FALSE} q#! enter = FALSE ``` ## Send interrupt We can simulate pressing **CTRL-C** to quit long-running processes: ```{bash sleep, keep_last_prompt = TRUE} sleep 1000 #! expect_prompt = FALSE C-c #! wait = 1, literal = FALSE, expect_prompt = TRUE ``` *View the corresponding [bash.Rmd file](https://raw.githubusercontent.com/jeroenjanssens/knitractive/master/vignettes/examples/bash.Rmd) to learn more about how this page was generated.*