Skip to content
Snippets Groups Projects
Commit fa33852f authored by Alexander Schoch's avatar Alexander Schoch
Browse files

replace jshon with jq, as jshon is not as available and is also more cumbersome

parent 272452c2
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -202,7 +202,7 @@ This exercise requires you to parse strings to display them nicely. That can be
#!/bin/bash
curl -A 'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)' -s https://www.reddit.com/r/showerthoughts.json \
| jshon -e data -e children -a -e data -e title \
| jq ".data.children[].data.title" \
| shuf -n 1 \
| sed 's/\\//g' \
| sed 's/^"//' \
......
No preview for this file type
......@@ -950,19 +950,19 @@ such a daemon.
# display only the first few lines of a very long text file
head verylongtext.txt
**jshon**
**jq**
`jshon` is a very simple command-line json parser. It can read data in json format and return specific values.
`jq` is a very simple command-line json parser. It can read data in json format and return specific values.
Its most important options are `-e` and `-a`. `-e` extracts the value of a given key from a json array or object:
# Find the object with key "title" from a json object stored in the file "json"
jshon -e 'title' < 'json'
jq '.title' < 'json'
The `-a` option maps all remaining options across the currently selected element. It has to be combined with other options, for example the `-e` option.
# Find the names of all elements stored in the json object in file "json"
jshon -a -e 'name' < 'json'
jq '[].name' < 'json'
**shuf**
......
No preview for this file type
#!/bin/bash
echo "Building pdf..."
pandoc -t beamer --template template.tex --listings pres.md -o pres-part.pdf --pdf-engine pdflatex \
&& pandoc -t beamer --template template.tex --listings firstslide.md -o firstslide.pdf --pdf-engine pdflatex \
&& pdfunite firstslide.pdf pres-part.pdf pres.pdf \
&& rm firstslide.pdf pres-part.pdf \
pandoc -t beamer --template template.tex --listings pres.md -o pres.pdf --pdf-engine pdflatex \
&& echo "Build successful"
# Welcome to the Bash Workshop!
* Please turn of your camera for the lecture part of the course, we only have 2GB of RAM on this server
* If there are any technical problems, let me know!
---
author:
- Nicolas König
- Alexander Schoch
title: Bash Workshop
---
......@@ -53,10 +53,10 @@ title: Bash Workshop
echo Bash is awesome
# Now some fun stuff:
sudo zypper update
sudo dnf update
notify-send 'Update complete'
feh --bg-fill 'pictures/fancy_wallpaper.jpg'
youtube-dl -o 'Video.%(ext)s' 'https://www.youtube.com/watch?v=lAIGb1lfpBw'
youtube-dl -o 'Video.%(ext)s' 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'
### What bash can do
......@@ -171,13 +171,13 @@ title: Bash Workshop
### Bash doesn’t only run commands
* *Tilde expansion*\
`~/files` becomes `/home/alinea/files`
`~/files` becomes `/home/alex/files`
* *Variable expansion*\
`$BROWSER` becomes `Firefox`
* *Arithmetic expansion*\
`$(( 1 + 4 ))` becomes `5`
* *Command substitution*\
`$( pwd )` becomes `/home/alinea/scripts`
`$( pwd )` becomes `/home/alex/scripts`
* *Pathname expansion* (or *globbing*)\
`files/qui*` becomes `files/quicknotes files/quiz`
......@@ -187,7 +187,7 @@ title: Bash Workshop
* Double quotes (") don't prevent expansion, but single quotes (') do.
$ echo "$HOME" '$HOME'
/home/alinea $HOME
/home/alex $HOME
* Expansion happens *before word splitting*
......
No preview for this file type
......@@ -5,8 +5,8 @@ echo Hello World
echo Bash is awesome
# Now some fun stuff:
sudo zypper update
sudo dnf update
notify-send "Update complete"
feh --bg-fill "pictures/fancy_wallpaper.jpg"
youtube-dl -o "Video.%(ext)s" "https://www.youtube.com/watch?v=lAIGb1lfpBw"
youtube-dl -o "Video.%(ext)s" "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment