Player FM - Internet Radio Done Right
Checked 23d ago
הוסף לפני five שנים
תוכן מסופק על ידי HPR Volunteer and Hacker Public Radio. כל תוכן הפודקאסטים כולל פרקים, גרפיקה ותיאורי פודקאסטים מועלים ומסופקים ישירות על ידי HPR Volunteer and Hacker Public Radio או שותף פלטפורמת הפודקאסט שלהם. אם אתה מאמין שמישהו משתמש ביצירה שלך המוגנת בזכויות יוצרים ללא רשותך, אתה יכול לעקוב אחר התהליך המתואר כאן https://he.player.fm/legal.
Player FM - אפליקציית פודקאסט
התחל במצב לא מקוון עם האפליקציה Player FM !
התחל במצב לא מקוון עם האפליקציה Player FM !
פודקאסטים ששווה להאזין
בחסות
S
Squid Game: The Official Podcast


Squid Game is back—and this time, the knives are out. In the thrilling Season 3 premiere, Player 456 is spiraling and a brutal round of hide-and-seek forces players to kill or be killed. Hosts Phil Yu and Kiera Please break down Gi-hun’s descent into vengeance, Guard 011’s daring betrayal of the Game, and the shocking moment players are forced to choose between murdering their friends… or dying. Then, Carlos Juico and Gavin Ruta from the Jumpers Jump podcast join us to unpack their wild theories for the season. Plus, Phil and Kiera face off in a high-stakes round of “Hot Sweet Potato.” SPOILER ALERT! Make sure you watch Squid Game Season 3 Episode 1 before listening on. Play one last time. IG - @SquidGameNetflix X (f.k.a. Twitter) - @SquidGame Check out more from Phil Yu @angryasianman , Kiera Please @kieraplease and the Jumpers Jump podcast Listen to more from Netflix Podcasts . Squid Game: The Official Podcast is produced by Netflix and The Mash-Up Americans.…
HPR4373: Rsync with stdin as source
Manage episode 481057698 series 2795599
תוכן מסופק על ידי HPR Volunteer and Hacker Public Radio. כל תוכן הפודקאסטים כולל פרקים, גרפיקה ותיאורי פודקאסטים מועלים ומסופקים ישירות על ידי HPR Volunteer and Hacker Public Radio או שותף פלטפורמת הפודקאסט שלהם. אם אתה מאמין שמישהו משתמש ביצירה שלך המוגנת בזכויות יוצרים ללא רשותך, אתה יכול לעקוב אחר התהליך המתואר כאן https://he.player.fm/legal.
This show has been flagged as Explicit by the host.
In today's show, oxo show us how you can use the output of the find command with -print0 option to rsync files to another location.
find . -type f -mmin -230 -print0 | rsync -aAXv --info=progress2,stats --progress --from0 --files-from - . dst
116 פרקים
Manage episode 481057698 series 2795599
תוכן מסופק על ידי HPR Volunteer and Hacker Public Radio. כל תוכן הפודקאסטים כולל פרקים, גרפיקה ותיאורי פודקאסטים מועלים ומסופקים ישירות על ידי HPR Volunteer and Hacker Public Radio או שותף פלטפורמת הפודקאסט שלהם. אם אתה מאמין שמישהו משתמש ביצירה שלך המוגנת בזכויות יוצרים ללא רשותך, אתה יכול לעקוב אחר התהליך המתואר כאן https://he.player.fm/legal.
This show has been flagged as Explicit by the host.
In today's show, oxo show us how you can use the output of the find command with -print0 option to rsync files to another location.
find . -type f -mmin -230 -print0 | rsync -aAXv --info=progress2,stats --progress --from0 --files-from - . dst
116 פרקים
Toate episoadele
×This show has been flagged as Explicit by the host. hajime This installation script installs an Arch Linux system on an x64 architecture. The installation can be done with or without a network connection (internet). oxo/hajime - Codeberg.org hajime/make-recov at main - oxo/hajime - Codeberg.org isolatest/isolatest at main - oxo/isolatest - Codeberg.org Provide feedback on this episode .…
H
Hacker Public Radio

This show has been flagged as Explicit by the host. font selection Nerd Fonts - Iconic font aggregator, glyphs/icons collection, & fonts patcher Programming Fonts - Test Drive font installation install font package % yay -Sy $font_package update font database % fc-cache --force --verbose verify available fonts % fc-list | grep $font_name change font in application configs e.g.: alacritty emacs sway tofi Provide feedback on this episode .…
H
Hacker Public Radio

This show has been flagged as Explicit by the host. In today's show, oxo show us how you can use the output of the find command with -print0 option to rsync files to another location. find . -type f -mmin -230 -print0 | rsync -aAXv --info=progress2,stats --progress --from0 --files-from - . dst Provide feedback on this episode .…
H
Hacker Public Radio

This show has been flagged as Explicit by the host. Hi listener! My name is oxo. In this first episode for HPR I will introduce myself a little and present my plans for my future episodes on this channel. My goal is to let you as a listener follow along while I am learning new interesting things about Linux. This will be mainly about how I manage to survive the commandline while having fun doing so! :) My main codebase is in the codeberg repository, which you can find here: oxo - Codeberg.org Comments are always welcome! Please contact me via Mastodon: @oxo@qoto.org or email oxo at protonmail.com Provide feedback on this episode .…
This show has been flagged as Clean by the host. Make a diff: $ diff --unified --new-file --recursive original/ my-revision/ > my.patch Send my.patch to somebody so they can use it as input for the patch command: $ patch --strip 0 < my.patch Provide feedback on this episode .
H
Hacker Public Radio

This show has been flagged as Clean by the host. Today I Learnt more Bash tips Sgoti talks about supplying options to bash scripts Tags: Bash tips, TIL, getopts #!/bin/bash # License: GPL v3 # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . #Name: showtime.sh #Purpose: Time to make a show. #Version: beta 0.01 #Author: SGOTI (Some Guy On The Internet) #Date: 2023-12-29 #variables: bindir=/usr/bin/ cat=${bindir}cat date=${bindir}date echo=${bindir}echo mkdir=${bindir}mkdir dirshow0=${HOME}/Music/hpr/shows dirshow1=${dirshow0}/$(${date} +%Y) dirqueue=${dirshow1}/queue/$(${date} +%F) dirreserve=${dirshow1}/reserve-queue/$(${date} +%F) #start: function help() { ${cat} << EOH Usage: $0 [-s] [-r] [-q] [-h] name-of-show -s (Regular queue) -r (Reserve queue) -q (quit) -h (help) Examples: $0 -s name-of-show $0 -r name-of-show $0 -q $0 -h EOH } ## Use `getopts` to read user option into script. ## while getopts ":s:r:q:h" option; do case $option in s) show=$OPTARG function mkq () { ${mkdir} -v -p ${dirqueue}/${show}/edit; ${mkdir} -v -p ${dirqueue}/${show}/prod; ${cat} > ${dirqueue}/${show}/edit/${show}.md << _EOD_ # ${show} # ## subtitle ## - Tags: This work is licensed under a [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/ "CC-BY-SA 4.0 International"). _EOD_ builtin pushd -n ${dirqueue}/${show}/edit; builtin pushd -n ${dirqueue}/${show}/prod; } if [ -d ${dirshow1} ]; then mkq else ${echo} "Good Heavens! It's a new year."; ${mkdir} -v -p ${dirshow1}; mkq fi ;; r) reserve=$OPTARG function mkr () { ${mkdir} -v -p ${dirreserve}/${reserve}/edit; ${mkdir} -v -p ${dirreserve}/${reserve}/prod; ${cat} > ${dirreserve}/${reserve}/edit/${reserve}.md << _EOD_ # ${reserve} # ## subtitle ## - Tags: This work is licensed under a [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/ "CC-BY-SA 4.0 International"). _EOD_ builtin pushd -n ${dirreserve}/${reserve}/edit; builtin pushd -n ${dirreserve}/${reserve}/prod; } if [ -d ${dirshow1} ]; then mkr else ${echo} "Good Heavens! It's a new year."; ${mkdir} -v -p ${dirshow1}; mkr fi ;; q) ${echo} "Goodbye."; exit ;; h) help exit ;; *) if [ -z "${option}" ]; then help exit 1 fi ${echo} "Good Heavens! Invalid input."; help exit ;; esac done exit; #!/bin/bash # License: GPL v3 # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . #Name: sc.sh #Purpose: #Version: beta 0.01 #Author: SGOTI (Some Guy On The Internet) #Date: 2023-12-31 #variables: bindir=/usr/bin/ cat=${bindir}cat date=${bindir}date echo=${bindir}echo ls=${bindir}ls screen=${bindir}screen #start: ${echo} -e "\nStep 0: $(${date} +%F), $(${date} +%T)"; function help() { ${cat} << EOH Usage: $0 [-b] [-s] [-k] [-h] name-of-show -b [y|n] (Create or kill, base sockets.) -s (Create new sockets.) -k (Kill sockets.) -h (help menu) Examples: $0 -b y $0 -b n $0 -s name-of-socket $0 -k name-of-socket $0 -h EOH } ${echo} -e "\nStep 1: $(${date} +%F), $(${date} +%T)"; while getopts ":b:s:k:h:" option; do case "${option}" in b) userinput0=$OPTARG if [ ${userinput0} == "y" ]; then ${screen} -dmS apps; ${screen} -dmS jobby; ${screen} -ls; elif [ ${userinput0} == "n" ]; then # You don't need the entire name to kill the socket. ${screen} -X -S "app" kill ${screen} -X -S "job" kill ${screen} -ls; else ${echo} "Good Heavens!" ${screen} -ls; help exit 1 fi ;; s) userinput0=$OPTARG ${screen} -dmS "${userinput0}"; clear ${screen} -ls; ${echo} -e "\nNew sockets: $(${date} +%F), $(${date} +%T)"; ;; k) userinput0=$OPTARG ${screen} -XS ${userinput0} kill clear ${screen} -ls; ${echo} -e "\nKill sockets: $(${date} +%F), $(${date} +%T)"; ;; h) help ${echo} -e "\nHelp menu: $(${date} +%F), $(${date} +%T)"; exit ;; *) if [ -z "${option}" ]; then help exit 1 fi ${echo} "Good Heavens! Invalid input."; help exit ;; esac done ${echo} -e "\nStep 2: $(${date} +%F), $(${date} +%T)"; exit; Source: In-Depth Series: Today I Learnt Source: In-Depth Series: Bash Scripting This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License . Provide feedback on this episode .…
This show has been flagged as Explicit by the host. Overview Recently Ken Fallon did a show on HPR, number 3962 , in which he used a Bash pipeline of multiple commands feeding their output into a while loop. In the loop he processed the lines produced by the pipeline and used what he found to download audio files belonging to a series with wget . This was a great show and contained some excellent advice, but the use of the format: pipeline | while read variable; do ... reminded me of the "gotcha" I mentioned in my own show 2699 . I thought it might be a good time to revisit this subject. So, what's the problem? The problem can be summarised as a side effect of pipelines. What are pipelines? Pipelines are an amazingly useful feature of Bash (and other shells). The general format is: command1 | command2 ... Here command1 runs in a subshell and produces output (on its standard output ) which is connected via the pipe symbol ( | ) to command2 where it becomes its standard input . Many commands can be linked together in this way to achieve some powerful combined effects. A very simple example of a pipeline might be: $ printf 'World\nHello\n' | sort Hello World The printf command (≡ 'command1' ) writes two lines (separated by newlines) on standard output and this is passed to the sort command's standard input (≡ 'command2' ) which then sorts these lines alphabetically. Commands in the pipeline can be more complex than this, and in the case we are discussing we can include a loop command such as while . For example: $ printf 'World\nHello\n' | sort | while read line; do echo "($line)"; done (Hello) (World) Here, each line output by the sort command is read into the variable line in the while loop and is written out enclosed in parentheses. Note that the loop is written on one line. The semi-colons are used instead of the equivalent newlines. Variables and subshells What if the lines output by the loop need to be numbered? $ i=0; printf 'World\nHello\n' | sort | while read line; do ((i++)); echo "$i) $line"; done 1) Hello 2) World Here the variable 'i' is set to zero before the pipeline. It could have been done on the line before of course. In the while loop the variable is incremented on each iteration and included in the output. You might expect 'i' to be 2 once the loop exits but it is not. It will be zero in fact. The reason is that there are two 'i' variables. One is created when it's set to zero at the start before the pipeline. The other one is created in the loop as a "clone". The expression: ((i++)) both creates the variable (where it is a copy of the one in the parent shell) and increments it. When the subshell in which the loop runs completes, it will delete this version of 'i' and the original one will simply contain the zero that it was originally set to. You can see what happens in this slightly different example: $ i=1; printf 'World\nHello\n' | sort | while read line; do ((i++)); echo "$i) $line"; done 2) Hello 3) World $ echo $i 1 These examples are fine, assuming the contents of variable 'i' incremented in the loop are not needed outside it. The thing to remember is that the same variable name used in a subshell is a different variable; it is initialised with the value of the "parent" variable but any changes are not passed back. How to avoid the loss of changes in the loop To solve this the loop needs to be run in the original shell, not a subshell. The pipeline which is being read needs to be attached to the loop in a different way: $ i=0; while read line; do ((i++)); echo "$i) $line"; done < <(printf 'World\nHello\n' | sort) 1) Hello 2) World $ echo $i 2 What is being used here is process substitution . A list of commands or pipelines are enclosed with parentheses and a 'less than' sign prepended to the list (with no intervening spaces). This is functionally equivalent to a (temporary) file of data. The redirection feature allows for data being read from a file in a loop. The general format of the command is: while read variable do # Use the variable done < file Using process substitution instead of a file will achieve what is required if computations are being done in the loop and the results are wanted after it has finished. Beware of this type of construct The following one-line command sequence looks similar to the version using process substitution, but is just another form of pipeline: $ i=0; while read line; do echo $line; ((i++)); done < /etc/passwd | head -n 5; echo $i root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync 0 This will display the first 5 lines of the file but does it by reading and writing the entire file and only showing the first 5 lines of what is written by the loop. What is more, because the while is in a subshell in a pipeline changes to variable 'i' will be lost. Advice Use the pipe-connected-to-loop layout if you're aware of the pitfalls, but will not be affected by them. Use the read-from-process-substitution format if you want your loop to be complex and to read and write variables in the script. Personally, I always use the second form in scripts, but if I'm writing a temporary one-line thing on the command line I usually use the first form. Tracing pipelines (advanced) I have always wondered about processes in Unix. The process you log in to, normally called a shell runs a command language interpreter that executes commands read from the standard input or from a file. There are several such interpreters available, but we're dealing with bash here. Processes are fairly lightweight entities in Unix/Linux. They can be created and destroyed quickly, with minimal overhead. I used to work with Digital Equipment Corporation's OpenVMS operating system which also uses processes - but these are much more expensive to create and destroy, and therefore slow and less readily used! Bash pipelines, as discussed, use subshells . The description in the Bash man page says: Each command in a multi-command pipeline, where pipes are created, is executed in a subshell, which is a separate process. So a subshell in this context is basically another child process of the main login process (or other parent process), running Bash. Processes (subshells) can be created in other ways. One is to place a collection of commands in parentheses. These can be simple Bash commands, separated by semi-colons, or pipelines. For example: $ (echo "World"; echo "Hello") | sort Hello World Here the strings "World" and "Hello" , each followed by a newline are created in a subshell and written to standard output. These strings are piped to sort and the end result is as shown. Note that this is different from this example: $ echo "World"; echo "Hello" | sort World Hello In this case "World" is written in a separate command, then "Hello" is written to a pipeline. All sort sees is the output from the second echo , which explains the output. Each process has a unique numeric id value (the process id or PID ). These can be seen with tools like ps or htop . Each process holds its own PID in a Bash variable called BASHPID . Knowing all of this I decided to modify Ken's script from show 3962 to show the processes being created - mainly for my interest, to get a better understanding of how Bash works. I am including it here in case it may be of interest to others. #!/bin/bash series_url="https://hackerpublicradio.org/hpr_mp3_rss.php?series=42&full=1&gomax=1" download_dir="./" pidfile="/tmp/hpr3962.sh.out" count=0 echo "Starting PID is $BASHPID" > $pidfile (echo "[1] $BASHPID" >> "$pidfile"; wget -q "${series_url}" -O -) |\ (echo "[2] $BASHPID" >> "$pidfile"; xmlstarlet sel -T -t -m 'rss/channel/item' -v 'concat(enclosure/@url, "→", title)' -n -) |\ (echo "[3] $BASHPID" >> "$pidfile"; sort) |\ while read -r episode; do [ $count -le 1 ] && echo "[4] $BASHPID" >> "$pidfile" ((count++)) url="$( echo "${episode}" | awk -F '→' '{print $1}' )" ext="$( basename "${url}" )" title="$( echo "${episode}" | awk -F '→' '{print $2}' | sed -e 's/[^A-Za-z0-9]/_/g' )" #wget "${url}" -O "${download_dir}/${title}.${ext}" done echo "Final value of \$count = $count" echo "Run 'cat $pidfile' to see the PID numbers" The point of doing this is to get information about the pipeline which feeds data into the while loop . I kept the rest intact but commented out the wget command. For each component of the pipeline I added an echo command and enclosed it and the original command in parentheses, thus making a multi-command process. The echo commands write a fixed number so you can tell which one is being executed, and it also writes the contents of BASHPID . The whole thing writes to a temporary file /tmp/hpr3962.sh.out which can be examined once the script has finished. When the script is run it writes the following: $ ./hpr3962.sh Final value of $count = 0 Run 'cat /tmp/hpr3962.sh.out' to see the PID numbers The file mentioned contains: Starting PID is 80255 [1] 80256 [2] 80257 [3] 80258 [4] 80259 [4] 80259 Note that the PID values are incremental. There is no guarantee that this will be so. It will depend on whatever else the machine is doing. Message number 4 is the same for every loop iteration, so I stopped it being written after two instances. The initial PID is the process running the script, not the login (parent) PID. You can see that each command in the pipeline runs in a separate process ( subshell ), including the loop. Given that a standard pipeline generates a process per command, I was slightly surprised that the PID numbers were consecutive. It seems that Bash optimises things so that only one process is run for each element of the pipe. I expect that it would be possible for more processes to be created by having pipelines within these parenthesised lists, but I haven't tried it! I found this test script quite revealing. I hope you find it useful too. Links Bash pipelines: GNU Bash manual: 3.2.3 Pipelines Bash loops: GNU Bash manual: 3.2.5.1 Looping Constructs Bash process substitution: GNU Bash manual: 3.5.6 Process Substitution HPR shows referenced: hpr2045 :: Some other Bash tips hpr2699 :: Bash Tips - 15 hpr3962 :: It's your data Provide feedback on this episode .…
This show has been flagged as Clean by the host. This is a response show to hpr3959 :: Download any HPR series with english file names "A dir with the series name will be created and all shows will be renamed to ShowTitle.mp3 inside it" This was the first show by gemlog and he used Bash, sed, grep, wget, to scrape the HPR site. This is great but as he points out any change to the site will break the script. A safer way to get the episodes is by scraping the rss feed, and the following is an example of how you might do that #!/bin/bash series_url="https://hackerpublicradio.org/hpr_mp3_rss.php?series=42&full=1&gomax=1" download_dir="./" wget "${series_url}" -O - | xmlstarlet sel -T -t -m 'rss/channel/item' -v 'concat(enclosure/@url, "→", title)' -n - | sort | while read episode do url="$( echo ${episode} | awk -F '→' '{print $1}' )" ext="$( basename "${url}" )" title="$( echo ${episode} | awk -F '→' '{print $2}' | sed -e 's/[^A-Za-z0-9]/_/g' )" wget "${url}" -O "${download_dir}/${title}.${ext}" done Provide feedback on this episode .…
This show has been flagged as Explicit by the host. Hello all. This is gemlog from Terrace, bc, canada just up near the alaska panhandle. Some of you may know me from in COM chat on sdf dot org or as a fedizen on the tilde dot zone instance of mastodon. Now, the other day I finally got around to checking out HPR properly, even though my masto-pal claw-dio-m turned me on to it a couple of years ago. Recently, on a friday night in irc on tilde radio, I noticed there were whole series on hpr and not only single shows and that got me kind of excited. I guess I'm easily excitable. Anyhow, something I could listen to at work or while driving. Still, I managed to forget about it until /just/ before I was leaving the house for work on Monday morning. I rushed to copy over a few shows - nearly at random onto my phone and headed out to work. After I got my morning sorted at work, I told VLC to play-all and enjoyed a couple of shows. I noticed that each show I had chosen had a beg post at the beginning. I figured I could make one on at least something from my messy gemlog/bin dir. However, after a break, I came back and couldn't remember which 4 digit numbered dot mp3 I had finished up on, which mildly irked me. Well, as we all know, irk becomes itch and I put my sad regex skills to the test scraping the hpr website with a custom bash script later when I got home. A very custom bash script. Like all scrapers, if any of the guys at hpr even breathe the wrong way, it will probably break horribly. On the other hand, I've had scrapers that looked just as sad running for many years against a canadian government site. So. Who knows? All the script uses are some built-ins from bash along with sed and wget for the actual getting. My local instance of searX N G was left smoking as scrambled for sed incantations to string together. I'm not a sed guy. Usage is simple, as the script only accepts one argument: ... the four digit series number of the show you want to download. It will create a dir with the series name and download every mp3 it finds, renaming each show to the show title. I was tempted to doll it up with some niceties like options for download dir, a selector for a series with a dialog of some kind... yada yada yada. But... we all know what happens when you stretch a quick hack with a bash script too far for the scripting language: hours of misery wishing you'd started with some other language. So far, I've used the script to download 8 series. DU dash S H tells me they add up to 2 dot 2 gig, so it seems to work well enough. It comes with the same iron clad warranty as everything I write: If it breaks, you get to keep all the pieces. Thanks for listening. #!/bin/bash # gemlog@gemlog.ca 2023-08-26 # License: CC BY-SA 4.0. # not proud of my continuing lack of regex foo frankly... if [ $# -lt 1 ]; then echo 1>&2 "$0: You need to enter the HPR Series Number to download as 4 digits" echo "The full list of HPR Series is at https://hackerpublicradio.org/series/index.html " exit 2 fi snumber=$1 re='^[[:digit:]]{4}$' if [[ $snumber =~ $re ]]; then wget https://hackerpublicradio.org/series/$snumber.html -q -O /tmp/$snumber.html content=$(]*>//g;/]*>//g;/]*>//g;/ Provide feedback on this episode .…
This show has been flagged as Explicit by the host. HPR Shows by Klaatu. Source: hpr3887 :: 10 must-know commands for a new cloud admin. Source: hpr3882 :: Alternatives to the cd command. Hot sauce lady. Source: Franks Red Hot Queen 2011. pwd && ls --group-directories-first --classify --almost-all # some more ls aliases alias la='ls -l --human-readable --group-directories-first --classify --almost-all' alias ll='ls --group-directories-first --classify --almost-all' alias lr='ls -l --human-readable --group-directories-first --classify --recursive' alias lar='ls -l --human-readable --group-directories-first --classify --almost-all --recursive' alias lap='ls -l --human-readable --group-directories-first --classify --almost-all | less' # safety first ;) alias rmi='rm --interactive --verbose' alias mvi='mv --interactive --verbose' alias cpi='cp --interactive --verbose' alias .shred='bleachbit --shred' # cd multi dir alias ..='cd ..;' alias .2='cd ../..;' alias .3='cd ../../..;' alias .4='cd ../../../..;' alias .5='cd ../../../../..;' # Directory controls. function cd () { clear; builtin cd "$@" && ls --group-directories-first --classify --almost-all; history -w; } #function pp () { #builtin pushd +$@ && ls --group-directories-first --classify --almost-all #} function pushup (){ builtin pushd $HOME/.config/vim/sessions/ builtin pushd $HOME/.local/bin/ builtin pushd $HOME/.thunderbird/*.default-release/ builtin pushd $HOME/Documents/non-of-your-business/ builtin pushd $HOME/Downloads/in/ builtin pushd $HOME/Downloads/out/ builtin pushd $HOME/Downloads/playground/ builtin pushd $HOME/Music/hpr/shows/ builtin pushd $HOME/projects/ builtin pushd $HOME/projects/hprbank/bp/ builtin pushd $HOME/symlinks/ builtin pushd $HOME/tmp/ builtin pushd +11 builtin dirs -v } alias pd='pushd' alias dirs='dirs -v' # Update alias .upg='sudo apt update && sudo apt upgrade -y;' # shutdown | reboot alias .sd='sudo shutdown -P now;' alias .rs='sudo reboot;' # Misc alias ccb='cat $HOME/cb | xsel --input --clipboard && echo "Copy. $(date "+%F %T")";' alias pcb='xsel --output --clipboard > $HOME/cb && echo "Copy. $(date "+%F %T")";' alias zz='xsel -c -b && echo "Clipboard Cleared. $(date "+%F %T")";' # File Mods alias 700='chmod --verbose =700' alias 600='chmod --verbose =600' alias 400='chmod --verbose =400' ############################################################################### # Functions ############################################################################### function .s () { ln --symbolic --verbose --target-directory=$HOME/symlinks/ $(pwd)/${1}; } function extract () { if [ -f $1 ] then case $1 in *.tar.bz2) tar -vxjf $1 ;; *.tar.gz) tar -vxzf $1 ;; *.tar) tar -xvf $1 ;; *.bz2) bunzip2 $1 ;; *.rar) unrar -x $1 ;; *.gz) gunzip $1 ;; *.tar) tar -vxf $1 ;; *.tbz2) tar -vxjf $1 ;; *.tgz) tar -vxzf $1 ;; *.zip) unzip $1 ;; *.Z) uncompress $1 ;; *.7z) 7z -x $1 ;; *) echo "Good Heavens, '$1' will NOT extract..." ;; esac else echo "Good Heavens, '$1' is NOT a valid file." fi } function myip () { ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/'; } function .mkd (){ mkdir -v $(date +%F) && pushd $(date +%F); } function .mkt (){ tmpdir=$(mktemp -d /tmp/$(date +%F).XXXXXXXX) && pushd ${tmpdir} } function .d (){ echo $(date +%F)$1 | xsel -i -b; } function .sh () { NEWSCRIPT=${1}.sh cat >> ${NEWSCRIPT} << EOS #!/bin/bash # License: GPL v3 # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . #Name: ${NEWSCRIPT} #Purpose: #Version: beta 0.01 #Author: SGOTI (Some Guy On The Internet) #Date: $(date +%F) #variables: #start: exit; EOS if [ -f "${NEWSCRIPT}" ] then chmod 700 ${NEWSCRIPT} else echo "Good Heavens! There isn't a "${NEWSCRIPT}"" fi } function .fmd () { xsel -o -b | fmt -w 76 | sed 's/$/ /g s/ / /g s/ / /g s/ / /g s/$/ /g s/ *$/ /g s/ / /g' | xsel -i -b; } #!/bin/bash # License: GPL v3 # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . #Name: bfn.sh #Purpose: Create better file names. #Version: beta 0.01 #Author: SGOTI (Some Guy On The Internet) #Date: 2022-11-08 #variables: oldname=$(echo ${1%.*}) newname=$(echo $oldname | sed 's/ /-/g;s/_/-/g;s/./-/g;s/--*/-/g;/\/d' | tr [:upper:] [:lower:]) ext1=".$(echo ${1##*.})" ext2=".$(echo ${1##*.} | tr [:upper:] [:lower:])" #start: function bcase () { if [ -f $1 ] then echo -e "renaming $oldnamen"; mv -v "$oldname$ext1" "$newname$ext2"; else mv -v "$oldname" "$newname"; fi } bcase exit; #!/bin/bash # License: GPL v3 # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . #Name: perm.sh #Purpose: #Version: beta 0.01 #Author: SGOTI (Some Guy On The Internet) #Date: 2023-01-13 #variables: var_dir=${1} #start: function bfp () { find "${var_dir}" -type d -exec chmod -R =700 {} + find "${var_dir}" -type f -exec chmod -R =600 {} + } bfp exit; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License . Provide feedback on this episode .…
H
Hacker Public Radio

Five or six ways I could think of to roam the files of your Linux computer without cd. pushd and popd dirs https://en.wikipedia.org/wiki/Pushd_and_popd The pushd command, when called with a filepath as an argument, saves the current working directory in memory (via a directory stack) so it can be returned to at any time, places the new filepath at the top of the stack, and changes to the new filepath. The popd command returns to the path at the top of the directory stack. cd - From man bash An argument of - is converted to $OLDPWD before the directory change is attempted. Variables EXPORT mydir="/path/to/file/" cd ${mydir} History and histverify Using !number from the history command will execute the command [user@pc ~]$ history 1 cd tmp 2 cd ~ 3 history [user@pc ~]$ !3 cd tmp [user@pc tmp]$ from the man command shopt [-pqsu] [-o] [optname ...] Toggle the values of settings controlling optional shell behavior. ... -s Enable (set) each optname. -u Disable (unset) each optname. Now using !number from the history command will put the command on the prompt but you need to execute it yourself [user@pc ~]$ shopt -s histverify [user@pc ~]$ !39673 [user@pc ~]$ cd tmp autocd command [ken@kalani ~]$ shopt -s autocd [ken@kalani ~]$ tmp cd -- tmp [ken@kalani tmp]$ ~ cd -- /home/ken working without changing to directory [ken@kalani ~]$ ls tmp…
H
Hacker Public Radio

A named pipe is like a UNIX pipe, except it takes the form of a file. $ mkfifo mypipe $ echo "Hacker Public Radio" > mypipe & $ cat mypipe Hacker Public Radio
H
Hacker Public Radio

Overview Have you ever written a Bash script (or any shell script) where you generate a message like 'Found 42 files' and the day comes when it reports 'Found 1 files'? Have you been irritated by this? I have, and I go to lengths to deal properly with (English) plurals in my Bash scripts. Method 1 The simplest solution would be to use an 'if' statement: if [[ $fcount -eq 1 ]]; then echo "Found 1 file" else echo "Found $fcount files" fi This works, but to have to do it for every message would be a pain! Method 2 The next approach to this problem might be to write a Bash function. pluralise () { local singular="${1}" local plural="${2}" local count="${3}" if [[ $count -eq 1 ]]; then echo "$singular" else echo "$plural" fi } This can be called as follows: $ i=1; echo "Found $i $(pluralise "file" "files" $i)" Found 1 file $ i=42; echo "Found $i $(pluralise "file" "files" $i)" Found 42 files The string being displayed with echo contains a command substitution ('$(command)') which returns 'file' or 'files' depending on the value given. The first two arguments can be more complex than plain strings: $ i=1; echo "There $(pluralise "is 1 light" "are $i lights" $i)" There is 1 light $ i=4; echo "There $(pluralise "is 1 light" "are $i lights" $i)" There are 4 lights The pluralise function is available for download. Method 3 The GNU project has developed a set of utilities called the GNU gettext utilities consisting of tools and documentation for translation. This is a large subject which is not suitable for a short HPR episode such as this one. Among the tools is 'ngettext' which performs the function we have been discussing - choosing among plural forms. It also implements translations if desired (and translation files are provided as part of the software being developed). We will not discuss the translation topic here, but the choice of plurals is something that can be used in Bash scripts. The 'ngettext' tool takes three mandatory parameters: MSGID - the singular form of the text MSGID-PLURAL - the plural form of the text COUNT - the value used to make the singular/plural choice There are other optional parameters and options but they are not relevant here. The tool can be used in exactly the same way as the 'pluralise' example above. $ i=1; echo "There $(ngettext "is 1 light" "are $i lights" $i)" There is 1 light $ i=4; echo "There $(ngettext "is 1 light" "are $i lights" $i)" There are 4 lights Whether you use this or a Bash function is your choice. Conclusion I have been using ngettext in my scripts since I discovered it. If you also need to provide messages in your projects in other languages then this might be a good idea. I admit that my understanding of the GNU gettext project is superficial, so, on reflection it might be better to use a Bash function, since I don’t currently need all of the features GNU gettext provides. Links…
Preamble This is a case where I came upon a thing in Bash I had never considered before and was pleased and surprised that there was a way of doing what I wanted to do! If this is completely obvious to you, apologies, but it wasn’t to me! Overview Many programming languages have the concept of short-circuit evaluation in Boolean expressions. What this means is that in an expression such as: A AND B if A is false then the whole expression must be false, and B doesn’t have to be evaluated. That is because both arguments to AND have to be true for the overall result to be true. If A is true on the other hand, then B has to be evaluated to determine if the overall result is true. Similarly with: A OR B if A is true then the whole expression must be true and B can be skipped without evaluation. This is because only one argument to OR needs to be true to return a true result. If A is false on the other hand, then B has to be evaluated to determine if the overall result is false. Both of these expressions are evaluated from left to right. This is not a given in all languages. Some use special operators such as 'and_then' and 'or_else' which explicitly perform short-circuiting and left-to-right evaluation. Definition In simple terms, short-circuiting is where the evaluation of an expression is stopped as soon as its outcome is determined. The Wikipedia article Short-circuit evaluation defines it as: Short-circuit evaluation, minimal evaluation, or McCarthy evaluation (after John McCarthy) is the semantics of some Boolean operators in some programming languages in which the second argument is executed or evaluated only if the first argument does not suffice to determine the value of the expression: when the first argument of the AND function evaluates to false, the overall value must be false; and when the first argument of the OR function evaluates to true, the overall value must be true. This article contains a table entitled Boolean operators in various languages which shows details of how various programming and scripting languages cater for this feature. Use case I was writing a Bash script in which I wanted to ask questions about various steps - should they be done or not? Alternatively, I wanted to be able to set an option to run without interaction and assume the answer is 'yes' to all questions. I’d encountered short-circuit evaluation before in Pascal and Perl so I wondered if I could use it in Bash. The expression I was trying to write was: if [[ $YES -eq 1 ]] || yes_no 'Create directory? %s ' 'N'; then # Create directory fi Variable YES is being set through an option '-Y'; it’s normally set to zero but is set to 1 if the option is used. yes_no is a function I wrote, and talked about in HPR episode 2096: “Useful Bash functions - part 2”. The requirement was that if YES was set to 1 I didn’t want the function…
Carl talks about a method to move function definitions to the bottom of a script using sed: #!/bin/sh source <(sed '1,/^exit/ d' $0) __say "hello" exit __say() { echo $1 } Guest Host #1 (scroll to the bottom to ruin the surprise) talks about the shift command using this example: startdate="$1" # Pick up date shift days=0 # Loop through args and create events while [ $1 ] ; do # as many times as you add a timestamp [ $1 != "off" ] && khal new $(date -j -v+"$days"d -f %Y-%m-%d +%Y-%m-%d $startdate) $1 8H Work let days++ shift done Guest Host #2 provides tips and examples on how to use variables safely and politely provide default values. One example of assigning a default value is: foo=${foo:-"blah"} Carl then closes out with the : (colon) shell builtin and provides a variation on the above default value: : ${foo:="blah"}…
Overview I write a moderate number of Bash scripts these days. Bash is not a programming language as such, but it’s quite powerful in what it can do by itself, and with other tools it’s capable of many things. I have enjoyed writing such scripts for many years on a variety of hardware and operating systems, and Bash is my favourite - partly because Linux itself is so flexible. This is just a short show describing three things I tend to do in Bash scripts to assist with some tasks I find I need to undertake. Generate Bash variables from a text file - usually output from a program Fill Bash arrays with data from a file or other source Use environment variables to control the Bash script’s execution Long notes Follow this link to read the detailed notes associated with this episode. Links Various links: What is the “eval” command in bash? A Complete Guide on How To Use Bash Arrays Bash mapfile builtin command Bash manual 3.7.1 Simple Command Expansion Previous episodes in this series about arrays: Bash Tips - 16 Bash Tips - 17 Bash Tips - 18 Bash Tips - 19 Bash Tips - 20…
Introduction I am in the process of rewriting some scripts I use to manage Magnatune albums. I’m a lifetime Magnatune member and have access to the whole music collection. I wrote a script for downloading albums and placing them in my ~/Music directory which I talked about in 2013 (show 1204). The original scripts are still available on GitLab and I know of one other person who made use of them! Since 2013 I have written a few other support scripts, for example one to manage a queue of albums I want to buy and download, and one which summarises the state of this queue. It’s this 'show_queue' script I am currently updating (called show_queue_orig, and available in the resources to this show). The original version of this script took Magnatune album URLs from a file (acting as a queue of stuff I wanted to buy), parsed out a piece of the URL and used it to grep a pre-prepared summary in another file. This file of summaries had been made from a master XML file provided by Magnatune (see update_albums on GitLab). Magnatune has moved away from this master XML file to a SQLite database in recent years, so I want to perform a database lookup for each URL to list its details. The first version of the new script wasn’t difficult to write: just extract the search data as before and run a query on the database using this data. I have included this script which I call show_queue_db_1 amongst the resources for this episode, so you can see what I’m talking about – and what I want to improve on. It felt bad to be performing multiple calls on the sqlite3 command in a loop, so I looked around for an alternative way. In April 2019 clacke did a show (number 2793) about the Bash coproc command. This command creates a subshell running a command or group of commands which is connected to the calling (parent) process through two file descriptors (FDs). It’s possible for the calling shell to write to the input descriptor and read from the output one and thereby communicate with whatever is running in the subshell. I was vaguely aware of coproc at the time of clacke’s show but hadn’t looked into it. I found the show fascinating but didn’t have a use for the feature at the time. To solve my need to show my Magnatune queue of future purchases, it looked as if a sqlite3 instance running in a subshell could be given queries one after the other and return the answers I needed. My journey to a Bash script using coproc then followed. Long notes Follow this link to read the detailed notes associated with this episode. Links Bash Reference Manual: 3.2.6 Coprocesses 3.6.8 Duplicating File Descriptors Stack Exchange: How do you use the command coproc in various shells? Wikipedia: Wikipedia page on expect Other links:…
Bash and quoted strings An issue I just hit in Bash was that I had a quoted string, and I wanted to enclose it in quotes. How to do this? This is the umpteenth time I have stumbled over this issue, and I realised I had found out how to solve it a while back but the information hadn’t rooted itself into my mind! I have always been less clear in my mind about quoted strings in Bash than I should be, so, assuming others might have similar confusion I thought I’d try and clarify things in the form of an HPR show. The problem The thing I was having difficulties with was an alias definition of a useful pipeline: nmap -sn 192.168.0.0/24 | awk '/^Nmap scan report/{print ""; print; next}{print}' This uses nmap (see Ken’s show 3052 for a discussion of its use) piped into an awk one-liner that formats the information returned by nmap. The alias command can be used to store such a command or command sequence as a single simple command. It’s usually added to the ~/.bashrc file so it gets added to every Bash shell you start up (note Bash Tips #22, currently being written, will cover these startup files). An alias definition looks something like this: alias la='ls -Al' The alias itself 'la' is defined as the command ls -Al. So how to make my nmap sequence into an alias given that the commands contain both single and double quotes? Quoted strings in Bash Bash is (to my mind) a bit weird with quoted strings. There are two sorts of quotes in Bash (leaving aside the backquote or backtick – `): Single quotes, also called hard quotes ('). The literal value of characters between the quotes is preserved. Single quotes are not allowed, even if preceded by backslash escape characters. Double quotes, also called soft quotes ("). Certain characters within the quotes have special meanings, such as '$' and '\'. Double quotes are allowed in the string when preceded by a backslash. There’s a more comprehensive treatment of these quoting types (and others) in the Bash Reference Manual. Changing quotes and concatenating strings To make a variable containing a string with embedded quotes you can do this: $ x='string1'"'"'string2' $ echo $x string1'string2 What we did here was close 'string1', start a new string enclosed in double quotes "'", then append a second string 'string2'. Bash treats the three strings as one, but they have to be contiguous. There must be no intervening spaces1. This solution is rather ugly. You could also use Bash string concatenation to do this, though it’s more long-winded: $ x='string1' $ x+="'" $ x+='string2' $ echo $x string1'string2 The same principles hold for double quotes of course: $ x="string1"'"'"string2" $ echo $x string1"string2 You’d probably not want to do this though. Using backslashes You can use bac…
The Environment (More collateral Bash tips) Overview You will probably have seen references to The Environment in various contexts relating to shells, shell scripts, scripts in other languages and compiled programs. In Unix and Unix-like operating systems an environment is maintained by the shell, and we will be looking at how Bash deals with this in this episode. When a script, program or subprocess is invoked it is given an array of strings called the environment. This is a list of name-value pairs, of the form name=value. Using the environment The environment is used to convey various pieces of information to the executing script or program. For example, two standard variables provided by the shell are 'HOME', which is set to the current user’s home directory and 'PWD, set to the current working directory. The shell user can set, change, remove and view environment variables for their own purposes as we will see in this episode. The Bash shell itself creates and in some cases manages environment variables. The environment contains global data which is passed down to subprocesses (child processes) by copying. However, it is not possible for a subprocess to pass information back to the superior (parent) process. Viewing the environment You can view the environment in a number of ways. From the command line the command printenv can do this (this is usually but not always a stand-alone command: it’s /usr/bin/printenv on my Debian system). We will look at this command later. The command env without any arguments does the same thing as printenv without arguments. This is actually a tool to run a program in a modified environment which we will look at later. The environment printing capability can be regarded as more of a bonus feature. Scripting languages like awk (as well as Python and Perl, to name just a few) can view and manipulate the environment. Compiled languages such as C can do this too of course. There are other commands that will show the environment, and we will look at some of these briefly. Changing variables in the environment The variables in the environment are not significantly different from the shell parameters we have seen throughout this Bash Tips series. The only difference is that they are marked for export to commands and sub-shells. You will often see variables (or parameters) in the environment referred to as environment variables. The Bash manual makes a distinction between ordinary parameters (variables) and environment variables, but many other sources are less precise about this in my experience. The standard variables in the environment have upper-case names (HOME, SHELL, PWD, etc), but there is no reason why a variable you create should not be in lower or mixed case. In fact, the Bash manual suggests that you should avoid using all upper-case names so as not to clash with Bash’s variables. Variables can be created and changed a number of ways. They can be set up at login time (globally or locally) through various standard configuration files. It is intended to look at this subject in an upcoming episode so we will leave discussing the subject until then. By preceding the command or script invocation with name=value expressions which will temporarily place these variables into the environment for the command Using the export command Using…
H
Hacker Public Radio

Overview I use pdmenu a lot to help me do work on my main desktop PC. I did an HPR show on pdmenu on 13 December 2017 and the author Joey Hess responded in show 2459. In the intervening time I have also integrated Zenity into my menus. This is a GUI tool which generates a number of different pop-up windows known as dialogs, which can display information, or into which information can be typed. The capabilities provided by pdmenu are a little too basic to enable me to do what I need to do. I thought it might be of interest to show some examples of how I use this tool with pdmenu. Long notes I have provided detailed notes as usual for this episode, and these can be viewed here. Links Pdmenu: Pdmenu website Joey Hess Zenity Wikipedia page Zenity Manual…
H
Hacker Public Radio

https://en.wikipedia.org/wiki/Scope_%28computer_science%29 In hpr2739, Dave talked briefly about local variables. But what are they? In most modern languages, especially in compiled languages, "local" means that the value of a variable cannot be directly known, by looking up the name, outside the bounds of that function, but that’s not how it works in bash. Languages like C and Python have lexical scope. Lexical scope means local variables are local in the text. The names are local. If I’m writing code that is textually located outside the function, I cannot even describe how to access the variables within the function, because myvariable in my function is not the same variable, not the same place, as myvariable in your function. Languages like Bash and Elisp have dynamic scope. That means local variables are local in time. The names are global. What happens when you declare a variable local in bash is that the existing value of that variable is stowed away, to be brought back when your function exits. #!/usr/bin/env bash function sayscope() { echo The scope is $whatsmyscope } function globalscope() { whatsmyscope=global } function dynamicscope() { whatsmyscope=dynamic } function localscope() { local whatsmyscope=local sayscope dynamicscope sayscope } globalscope sayscope localscope sayscope The scope is global The scope is local The scope is dynamic The scope is global Perl has both, and it calls them local (dynamic scope, like bash) and my (lexical scope): #!/usr/bin/env perl use v5.10; sub sayscope { say "Dynamic scope is $whatsmyscope"; } sub globalscope { $whatsmyscope="global"; } sub dynamicscope { $whatsmyscope="dynamic"; } sub lexicalscope { my $whatsmyscope="lexical"; say "Lexical scope is $whatsmyscope"; sayscope; } sub localscope { local $whatsmyscope="local"; sayscope; dynamicscope; sayscope; lexicalscope; } globalscope; sayscope; localscope; sayscope; Dynamic scope is global Dynamic scope is local Dynamic scope is dynamic Lexical scope is lexical Dynamic scope is dynamic Dynamic scope is global You almost never want to use local in Perl, it’s mostly there for historical reasons — lexical scope is a Perl 5 feature. https://perl.plover.com/local.html covers well the remaining few and narrow exceptions where local might be useful. As dynamic scope has some valid use, it’s available in some otherwise lexically scoped languages. For example, Common LISP has the special form, and several Schemes and Racket have parameter objects: https://www.lispworks.com/documentation/HyperSpec/Body/d_specia.htm https://srfi.schemers.org/srfi-39/srfi-39.html https://docs.racket-lang.org/reference/parameters.html To dig fully into the history and flora of dynamic and lexical scope merits another episode.…
If you want the full manuscript, that’s at gitlab: hpr2793_bash_coproc_manuscript.adoc. It’s almost a transcript, but I added spontaneous commentary while reading the examples, so that’s not in the manuscript. Episode errata: Command substitution with $() is perfectly valid according to POSIX, and is accepted both by dash and by bash --posix. It’s not to be considered a bashism. I fumbled the pronunciation of the printf format string in one place and said "parenthesis" instead of "percentage sign". I tried to say "space" every time there’s a space, but I know I forgot it in a few places. But you probably need to look at the show notes to really make sense of the commands anyway. Example #1: $ echo $(echo hacker public radio) hacker public radio $ $(echo echo hacker public radio) # It can even supply the command itself, not just parameters. Note the word splitting. hacker public radio $ "$(echo echo hacker public radio)" # Counteract word splitting by putting the command substitution in quotes. bash: echo hacker public radio: command not found $ `echo echo hacker public radio` # Old-style command substitution hacker public radio More on command substitution in Dave’s hpr1903: Some further Bash tips. Example #2: $ echo <(echo hacker public radio) /dev/fd/63 $ cat <(echo hacker public radio) hacker public radio You can also combine process substitution with redirection. Example #3: $ echo hacker public radio > >(sed -e 's/$/!/') # You need the space between the greater-thans here! hacker public radio!…
Tidying loose ends (Some collateral Bash tips) Deleting arrays I forgot to cover one thing on my list when doing the last show: I forgot to explain how to delete arrays and array elements. I’ll cover that topic in this episode. Positional and Special parameters I have also avoided talking much about the positional and special parameters in Bash: '$1', '$2', '$#' and the rest. I will cover (some of) these in this episode. Silly titles I stopped doing the weird episode titles by episode 14 because I thought the joke was getting tired. However, I think a few people missed them (and a certain HPR colleague was found vandalising my new titles as they were being posted ;-), so I have added them inside the notes on the older shows and am adding one here – as a homage to silliness. Long notes I have provided detailed notes as usual for this episode, and these can be viewed here. Links "GNU BASH Reference Manual" Section "3.4 Shell Parameters" Section "4 Shell Builtin Commands" Section "4.1 Bourne Shell Builtins" Section "4.2 Bash Builtin Commands" Section "4.3.1 The Set Builtin" POSIX Shell Command Language: unset HPR series: Bash Scripting Previous episodes under the heading Bash Tips: HPR episode 1648 "Bash parameter manipulation" HPR episode 1843 "Some Bash tips" HPR episode 1884 "Some more Bash tips" HPR episode 1903 "Some further Bash tips" HPR episode 1951 "Some additional Bash tips" HPR episode 2045 "Some other Bash tips" HPR episode 2278 "Some supplementary Bash tips" HPR episode 2293 "More supplementary Bash tips" HPR episode 2639 "Some ancillary Bash tips - 9" HPR episode 2649 "More ancillary Bash tips - 10" HPR episode 2659 "Further ancillary Bash tips - 11" HPR episode 2669 "Additional ancillary Bash tips - 12" HPR episode 2679 "Extra ancillary Bash tips - 13" HPR episode…
Arrays in Bash (Supplemental auxiliary Bash tips) This is the fourth and last of a small group of shows on the subject of arrays in Bash. It is also the nineteenth show in the Bash Tips sub-series. In the last show we continued with the subject of parameter expansion in the context of arrays. There are other aspects of this that could be looked at, but we’ll leave it for the moment and may revisit it in the future. In this episode we will look in more depth at the declare (typeset) built in command and at some commands that are related (readonly and local), We will also look at the commands that assist with loading data into arrays: mapfile (readarray) and read. Long notes As usual I have provided detailed notes and examples for this episode, and these can be viewed here. Links "GNU BASH Reference Manual" Section on "Bash Arrays" Section on "4 Shell Builtin Commands" Section on "4.1 Bourne Shell Builtins" Section on "4.2 Bash Builtin Commands" Linux Documentation Project: Advanced Bash-Scripting Guide Chapter 27: Arrays HPR series: Bash Scripting Previous episodes under the heading Bash Tips: HPR episode 1648 "Bash parameter manipulation" HPR episode 1843 "Some Bash tips" HPR episode 1884 "Some more Bash tips" HPR episode 1903 "Some further Bash tips" HPR episode 1951 "Some additional Bash tips" HPR episode 2045 "Some other Bash tips" HPR episode 2278 "Some supplementary Bash tips" HPR episode 2293 "More supplementary Bash tips" HPR episode 2639 "Some ancillary Bash tips - 9" HPR episode 2649 "More ancillary Bash tips - 10" HPR episode 2659 "Further ancillary Bash tips - 11" HPR episode 2669 "Additional ancillary Bash tips - 12" HPR episode 2679 "Extra ancillary Bash tips - 13" HPR episode 2689 "Bash Tips - 14 (Some auxiliary Bash tips)" HPR episode 2699 "Bash Tips - 15 (More auxiliary Bash tips)" HPR episod…
H
Hacker Public Radio

Introduction On January 4th 2019 Ken Fallon did a great show entitled hpr2720 :: Download youtube channels using the rss feeds where he presented a Bash script called youtube-rss.bash for managing YouTube downloads through RSS feeds. Ken said he welcomed constructive feedback ☺ When I see a Bash script these days I usually find myself looking for ways to rewrite it to make it fit in with what I have been learning while doing my Bash Tips sub-series. Either that or I find it’s got some better ideas than I’ve been using which I have to find out about. I also spend time going over my own old scripts (I was writing them in the 1990’s in some cases) and trying to incorporate newer Bash features. Suffice it to say that I spotted some areas for improvement in Ken’s script and thought this might be the way to share my thoughts about them. We’re low on shows as I write this, so that gave me more motivation to make a show rather than add a comment or send Ken an email. Apology: I’m still suffering from the aftermath of some flu-like illness so have had to edit coughing fits out of the audio at various points. If you detect any remnants then I’m sorry! Long notes I have provided detailed notes as usual for this episode, and these can be viewed here. Links HPR episode 2720 “hpr2720 :: Download youtube channels using the rss feeds” youtube-rss.bash Wikipedia article on cat Useless use of cat…
Bash Tips - 18 (Extra auxiliary Bash tips) Arrays in Bash This is the third of a small group of shows on the subject of arrays in Bash. It is also the eighteenth show in the Bash Tips sub-series. In the last show we looked at ways of accessing elements with negative indices and how to concatenate arrays. We then launched into parameter expansion in the context of arrays. There are a few more parameter expansion operations to look at in this episode, then in the next episode we will look in more depth at the declare built in command and at some of the commands that assist with loading data into arrays. Long notes I have provided detailed notes as usual for this episode, and these can be viewed here. Links "GNU BASH Reference Manual" Section on "Bash Arrays" Section on "Shell Parameter Expansion" Linux Documentation Project: Advanced Bash-Scripting Guide Chapter 27: Arrays HPR series: Bash Scripting Previous episodes under the heading Bash Tips: HPR episode 1648 "Bash parameter manipulation" HPR episode 1843 "Some Bash tips" HPR episode 1884 "Some more Bash tips" HPR episode 1903 "Some further Bash tips" HPR episode 1951 "Some additional Bash tips" HPR episode 2045 "Some other Bash tips" HPR episode 2278 "Some supplementary Bash tips" HPR episode 2293 "More supplementary Bash tips" HPR episode 2639 "Some ancillary Bash tips - 9" HPR episode 2649 "More ancillary Bash tips - 10" HPR episode 2659 "Further ancillary Bash tips - 11" HPR episode 2669 "Additional ancillary Bash tips - 12" HPR episode 2679 "Extra ancillary Bash tips - 13" HPR episode 2689 "Bash Tips - 14 (Some auxiliary Bash tips)" HPR episode 2699 "Bash Tips - 15 (More auxiliary Bash tips)" HPR episode 2709 "Bash Tips - 16 (Further auxiliary Bash tips)" HPR episode 2719 "Bash Tips - 17 (Additional auxiliary Bash tips)" Resources: Examples: bash18_ex1.sh, bash18_ex2.sh…
Bash Tips - 17 (Additional auxiliary Bash tips) Arrays in Bash This is the second of a small group of shows on the subject of arrays in Bash. It is also the seventeenth show in the Bash Tips sub-series. In the last show we saw the two types of arrays, and learned about the multiple ways of creating them and populating them. We also looked at how array elements and entire arrays are accessed. Now we want to continue looking at array access and some of the various parameter expansion operations available. Long notes I have provided detailed notes as usual for this episode, and these can be viewed here. Links "GNU BASH Reference Manual" Section on "Bash Arrays" Linux Documentation Project: Advanced Bash-Scripting Guide Chapter 27: Arrays Wikipedia article entitled "Fibonacci Number" HPR series: Bash Scripting Previous episodes under the heading Bash Tips: HPR episode 1648 "Bash parameter manipulation" HPR episode 1843 "Some Bash tips" HPR episode 1884 "Some more Bash tips" HPR episode 1903 "Some further Bash tips" HPR episode 1951 "Some additional Bash tips" HPR episode 2045 "Some other Bash tips" HPR episode 2278 "Some supplementary Bash tips" HPR episode 2293 "More supplementary Bash tips" HPR episode 2639 "Some ancillary Bash tips - 9" HPR episode 2649 "More ancillary Bash tips - 10" HPR episode 2659 "Further ancillary Bash tips - 11" HPR episode 2669 "Additional ancillary Bash tips - 12" HPR episode 2679 "Extra ancillary Bash tips - 13" HPR episode 2689 "Bash Tips - 14 (Some auxiliary Bash tips)" HPR episode 2699 "Bash Tips - 15 (More auxiliary Bash tips)" HPR episode 2709 "Bash Tips - 16 (Further auxiliary Bash tips)" Resources: Examples: bash17_ex1.sh, bash17_ex2.sh, bash17_ex3.sh, bash17_ex4.sh, bash17_ex5.sh…
Bash Tips - 16 (Further auxiliary Bash tips) Arrays in Bash This is the first of a small group of shows on the subject of arrays in Bash. It is also the sixteenth show in the Bash Tips sub-series. We have encountered Bash arrays at various points throughout this sub-series, and have even seen a number of examples, but the subject has never been examined in detail. This group of shows intends to make good this deficiency. Long notes I have provided detailed notes as usual for this episode, and these can be viewed here. Links "GNU BASH Reference Manual" Section on "Bash Arrays" Linux Documentation Project: Advanced Bash-Scripting Guide Chapter 27: Arrays HPR series: Bash Scripting Previous episodes under the heading Bash Tips: HPR episode 1648 "Bash parameter manipulation" HPR episode 1843 "Some Bash tips" HPR episode 1884 "Some more Bash tips" HPR episode 1903 "Some further Bash tips" HPR episode 1951 "Some additional Bash tips" HPR episode 2045 "Some other Bash tips" HPR episode 2278 "Some supplementary Bash tips" HPR episode 2293 "More supplementary Bash tips" HPR episode 2639 "Some ancillary Bash tips - 9" HPR episode 2649 "More ancillary Bash tips - 10" HPR episode 2659 "Further ancillary Bash tips - 11" HPR episode 2669 "Additional ancillary Bash tips - 12" HPR episode 2679 "Extra ancillary Bash tips - 13" HPR episode 2689 "Bash Tips - 14 (Some auxiliary Bash tips)" HPR episode 2699 "Bash Tips - 15 (More auxiliary Bash tips)" Resources: Examples: bash16_ex1.sh…
Bash Tips - 15 (More auxiliary Bash tips) Pitfalls for the unwary Bash loop user This is the fifteenth episode covering useful tips for Bash users. In the last episode we looked at the 'for' loop, and prior to that we looked at 'while' and 'until' loops. In this one I want to look at some of the loop-related issues that can trip up the unwary user. Loops in Bash are extremely useful, and they are not at all difficult to use in their basic forms. However, there are some perhaps less than obvious issues that can result in unexpected behaviour. Long notes I have provided detailed notes as usual for this episode, and these can be viewed here. Links "GNU BASH Reference Manual" "Bash Process Substitution" "GNU Findutils" HPR series: Bash Scripting Previous episodes under the heading Bash Tips: HPR episode 1648 "Bash parameter manipulation" HPR episode 1843 "Some Bash tips" HPR episode 1884 "Some more Bash tips" HPR episode 1903 "Some further Bash tips" HPR episode 1951 "Some additional Bash tips" HPR episode 2045 "Some other Bash tips" HPR episode 2278 "Some supplementary Bash tips" HPR episode 2293 "More supplementary Bash tips" HPR episode 2639 "Some ancillary Bash tips - 9" HPR episode 2649 "More ancillary Bash tips - 10" HPR episode 2659 "Further ancillary Bash tips - 11" HPR episode 2669 "Additional ancillary Bash tips - 12" HPR episode 2679 "Extra ancillary Bash tips - 13" HPR episode 2689 "Bash Tips - 14 (Some auxiliary Bash tips)" Resources: Examples: bash15_ex1.sh, bash15_ex2.sh…
Bash Tips - 14 (Some auxiliary Bash tips) More about loops This is the fourteenth episode covering useful tips about using Bash. Episodes 9-13 covered Making Decisions in Bash and in these episodes we looked at while and until loops, but not for loops. This episode is making good this deficiency, and is also looking at break and continue which are very useful when using loops. Long notes I have provided detailed notes as usual for this episode, and these can be viewed here. Links "GNU BASH Reference Manual" "Bash Looping Constructs" "Bash Shell Arithmetic" "Bourne Shell Builtins" "Bash Brace Expansion" HPR series: Bash Scripting Previous episodes under the heading Bash Tips: HPR episode 1648 "Bash parameter manipulation" HPR episode 1843 "Some Bash tips" HPR episode 1884 "Some more Bash tips" HPR episode 1903 "Some further Bash tips" HPR episode 1951 "Some additional Bash tips" HPR episode 2045 "Some other Bash tips" HPR episode 2278 "Some supplementary Bash tips" HPR episode 2293 "More supplementary Bash tips" HPR episode 2639 "Some ancillary Bash tips - 9" HPR episode 2649 "More ancillary Bash tips - 10" HPR episode 2659 "Further ancillary Bash tips - 11" HPR episode 2669 "Additional ancillary Bash tips - 12" HPR episode 2679 "Extra ancillary Bash tips - 13" Resources: Examples: bash14_ex1.sh, bash14_ex2.sh, bash14_ex3.sh, bash14_ex4.sh, bash14_ex5.sh…
H
Hacker Public Radio

Useful Bash functions - part 2 Overview This is the second show about Bash functions. In this one I revisit the yes_no function from the last episode and deal with some of the deficiencies of that version. As before it would be interesting to receive feedback on these versions of the function and would be great if other Bash users contributed ideas of their own. Full Notes Since the notes explaining this subject are long, they have been placed in a separate file. Click the link to see it. Links Previous HPR episode in this group Useful Bash functions: hpr1757…
H
Hacker Public Radio

Some other Bash tips Expansion As we saw in the last episode 1951 (and others in this sub-series) there are eight types of expansion applied to the command line in the following order: Brace expansion (we looked at this subject in episode 1884) Tilde expansion (seen in episode 1903) Parameter and variable expansion (this was covered in episode 1648) Command substitution (seen in episode 1903) Arithmetic expansion (seen in episode 1951) Process substitution Word splitting Pathname expansion We will look at process substitution and word splitting in this episode but since there is a lot to cover in these subjects, we'll save pathname expansion for the next episode. I have written out a moderately long set of notes about this subject and these are available by following this link. Links HPR episode 1648 "Bash parameter manipulation" HPR episode 1843 "Some Bash tips": HPR episode 1884 "Some more Bash tips": HPR episode 1903 "Some further Bash tips": HPR episode 1951 "Some additional Bash tips": "Introduction to sed" series on HPR: Part 1: hpr1976 Part 2: hpr1986 Part 3: hpr1997 Part 4: hpr2011 Wikipedia article on the "Named pipe": https://en.wikipedia.org/wiki/Named_pipe Wikipedia article on the "IFS" variable: https://en.wikipedia.org/wiki/Internal_field_separator Advanced Bash-Scripting Guide: Section 9.1 Bash Internal Variables (including IFS): https://www.tldp.org/LDP/abs/html/internalvariables.html…
H
Hacker Public Radio

Using the Incron file watching daemon Check out the man page for incron and also this write-up by Nixcraft. basic usage: incrontab -e In your editor of choice, follow this syntax: <path-to-watch> <event mask> command Links https://linux.die.net/man/5/incrontab https://www.cyberciti.biz/faq/linux-inotify-examples-to-replicate-directories/…
The Script: hpr1990.bash
The technique that started everything: https://www.pomodorotechnique.com/ The Pomodoro timer I used first, efficient, but left me stuck from one day to the other: https://www.tomato-timer.com/
H
Hacker Public Radio

In the show "hpr1943 :: HPR AudioBook Club 11.5 - Interview with David Collins-Rivera" pokey asked if there was a way to get the duration for media. The following three options springs to mind immediately. The first option is fix_tags and was written by our own Dave Morriss. $ date --utc --date="@$(echo $(fix_tags *mp3 *ogg 2>/dev/null | awk -F '\(|\)' '/length/ {print $2}' | sed 's/ sec//g' ) | sed 's/ /+/g' | bc )" +"%T" 03:09:49 Next up is mediainfo which provides a lot of information on media files. $ date -ud @$(echo $(mediainfo --full --Output=XML *mp3 *ogg | xmlstarlet sel -T -t -m "Mediainfo/File/track[@type='Audio']/Duration[1]" -v "." -n - | sed 's/.{3}$//') | sed 's/ /+/g' | bc) +"%T" 03:09:49 The last option is to use ffprobe from the ffmpeg team. $ date -ud @$(echo $(for i in *mp3 *ogg; do date -ud 1970-01-01T$(ffprobe -i $i 2>&1 | grep Duration | awk '{print $2}'| sed 's/,//g' ) +%s;done) | sed 's/ /+/g' | bc) +"%T" 03:09:49 For complete shownotes please click here.…
H
Hacker Public Radio

Some additional Bash tips Expansion As we saw in the last episode 1903 there are seven types of expansion applied to the command line in the following order: Brace expansion (we looked at this subject in episode 1884) Tilde expansion (seen in episode 1903) Parameter and variable expansion (this was covered in episode 1648) Command substitution (seen in episode 1903) Arithmetic expansion Word splitting Pathname expansion There is also another, process substitution, which occurs after arithmetic expansion on systems that can implement it. We will look at one more of these expansion types in this episode but since there is a lot to cover, we'll continue in a later episode. I have written out a moderately long set of notes about this subject. Click the link to see them. Audio Note This time, in the spirit of experimentation and as a way of learning Audacity I processed my audio thus: Turned the stereo tracks to mono Used a Noise Gate plug-in to reduce background noise (after "training" it on some silence) Performed a Truncate Silence pass to reduce the length of pauses Applied a small amount of amplification Let me know if this had any positive or negative effects on the end product. Links Bash Reference Manual: Arithmetic Expansion: https://www.gnu.org/software/bash/manual/html_node/Arithmetic-Expansion.html#Arithmetic-Expansion Shell Arithmetic: https://www.gnu.org/software/bash/manual/html_node/Shell-Arithmetic.html#Shell-Arithmetic HPR episode 1202 "LiTS 025: bc" hosted by Dann Washko: https://hackerpublicradio.org/eps/hpr1202/index.html HPR episode 1648 "Bash parameter manipulation": https://hackerpublicradio.org/eps/hpr1648/index.html HPR episode 1843 "Some Bash tips": https://hackerpublicradio.org/eps/hpr1843/index.html HPR episode 1884 "Some more Bash tips": https://hackerpublicradio.org/eps/hpr1884/index.html HPR episode 1903 "Some further Bash tips": https://hackerpublicradio.org/eps/hpr1903/index.html…
H
Hacker Public Radio

Some further Bash tips Expansion There are seven types of expansion applied to the command line in the following order: Brace expansion (we looked at this subject in the last episode 1884) Tilde expansion Parameter and variable expansion (this was covered in episode 1648) Command substitution Arithmetic expansion Word splitting Pathname expansion We will look at some more of these in this episode but since there is a lot to cover, we'll continue in a later episode. I have written out a moderately long set of notes about this subject and these are available by following this link. Links Bash Reference Manual: Tilde Expansion: https://www.gnu.org/software/bash/manual/html_node/Tilde-Expansion.html Command Substitution: https://www.gnu.org/software/bash/manual/html_node/Command-Substitution.html HPR episode 1648 "Bash parameter manipulation" HPR episode 1843 "Some Bash tips" HPR episode 1884 "Some more Bash tips"…
H
Hacker Public Radio

Some more Bash tips We looked at Parameter Expansion back in HPR episode 1648 where we saw how Bash variables could be used, checked and edited. There are other sorts of expansions within Bash, and we'll look at one called "Brace Expansion" in this episode, which follows on from episode 1843 "Some Bash tips". I have written out a moderately long set of notes about this subject and these are available by clicking this link. Links HPR episode 1648 "Bash parameter manipulation" HPR episode 1843 "Some Bash tips"…
Today I want to talk about three Bash commands: pushd popd dirs These let you change directory on a Linux system (and others which support Bash) but keep a record of where you have been in a stack structure. The stack can be viewed and manipulated with these commands as well. I have written out a moderately long set of notes about these commands and these are available by clicking this link.…
H
Hacker Public Radio

This is a quick summary of my alarm clock system, written in bash and highly unreliable. Hardware My preferred hardware platform is a Dell Mini 9. Software My alarm clock is an embarrassing combination of bash scripts and Audacious, my favorite media player. Any media player will do, as long as it's scriptable. How It Works There are currently two bash scripts in my crappy alarm setup. One script is called "wakeup" and the other is called "wakeup-at". wakeup is simply a wrapper that adds some error handling around audacious. It launches audacious if it can't find an instance running already, waits five seconds for it to get itself together, and then causes it to play. It is also currently broken, so the 'launching audacious' part doesn't work. I have to manually start audacious myself. FAILURE. wakeup script: #!/bin/bash audacious & sleep 5s audacious -p & You've noticed that the "wakeup" script doesn't actually have any timing involved; If you want to use it as an alarm, you get to combine it with the bash "sleep" command. This is not a failure, this is by design! An example alarm: sleep 8h; wakeup One problem with this methodology is that it requires math, and is prone to errors. If I'm going to sleep at 10:46:33 PM and need to wake up at 7:00 AM, I need to chain sleep commands together for each unit of time: sleep 7h; sleep 14m; sleep 27s; wakeup Get some of that math wrong, and you wake up at the wrong time. FAILURE. "wakeup-at" is a wrapper around "wakeup" that uses the "at" utility to schedule the wakeup script. So, instead of using multiple sleep commands, it accepts any of the time formats that at accepts: wakeup-at 7:00 AM wakeup-at 6:00AM 2018-02-02 wakeup-at teatime Here is the wakeup-at script: #!/bin/bash ## Make sure we have enough arguments if [ $# -lt 1 ] then echo "Usage: `basename $0` <time>" exit 1 fi echo "$@" ## Add custom time keywords case "$1" in "eternaldarkness") echo wakeup | at 3:33 AM ;; ## Catch-all; send all arguments to at *) echo wakeup | at $@ ;; esac If you make a syntax error, "at" tells you about it immediately. Its only failings are what it inherits from the original "wakeup" script.…
H
Hacker Public Radio

Summary In this episode I provide an overview of how I use bash to automate my process for orgainizing photographs on my computer. There are two main objectives of this script: Organize photographs in a folder structure that makes sense to me, e.g. 2015/2015-05-22 Allow me to back up my photographs using a variety of methods. Download the Script This script is hosted on Github and you can download the latest version using following command: git clone https://gist.github.com/81e489b2a7397bb17305.git Script #!/bin/bash shopt -s -o nounset # Create variables and configure script. declare -rx SCRIPT=${0##*/} declare TMPDIR=/tmp/photos declare -r CURRENTDIR=`pwd` declare FILES=$TMPDIR/* declare DESTINATION=/media/Tyr/Pictures/Photos declare -r GOOGLEUSER="tnyplz@gmail.com" declare -r OPTSTRING="-h, -d:" declare -r LONGOPTSTRING="help, destination-directory, no-google-backup, sd-card, tmp-dir, no-delete, backup" declare RESULT declare GOOGLE_BACKUP=true declare SD=false declare SDDIR declare NODELETE=false declare S3=false # Executable dependencies declare -rx find="/usr/bin/find" declare -rx gphoto2="/usr/bin/gphoto2" declare -rx google="/usr/bin/google" declare -rx dcraw="/usr/bin/dcraw" declare -rx rsync="/usr/bin/rsync" declare -rx rename="/usr/bin/rename" declare -rx tar="/usr/bin/tar" declare -rx s3cmd="/usr/bin/s3cmd" # Sanity Checks if test -z $BASH; then printf "$SCRIPT:$LINENO: please run this script with the BASH shelln" >&2 exit 192 fi # check for find if test ! -x $find; then printf "$SCRIPT:$LINENO: the $find command is not available -- abortingn" >&2 exit 192 fi # check for gphoto2 if test ! -x $gphoto2; then printf "$SCRIPT:$LINENO: the $gphoto2 command is not available -- abortingn" >&2 exit 192 fi # check for google if test ! -x $google; then printf "$SCRIPT:$LINENO: the $google command is not available -- abortingn" >&2 fi # check for dcraw if test ! -x $dcraw; then printf "$SCRIPT:$LINENO: the $dcraw command is not available -- abortingn" >&2 fi # check for rename if test ! -x $rename; then printf "$SCRIPT:$LINENO: the $rename command is not available -- abortingn" >&2 exit 192 fi # check for rsync if test ! -x $rsync; then printf "$SCRIPT:$LINENO: the $rsync command is not available -- abortingn" >&2 fi # check for tar if test ! -x $tar; then printf "$SCRIPT:$LINENO: the $tar command is not available -- abortingn" >&2 fi # check for glacier-cmd if test ! -x $s3cmd; then printf "$SCRIPT:$LINENO: the $s3cmd command is not available -- abortingn" >&2 fi # Check for Options # ================= getopt -T if [ $? -ne 4 ]; then printf "$SCRIPT:$LINENO: %sn" "getopt is in compatibility mode" >&2 exit 192 fi RESULT=$(getopt --name "$SCRIPT" --options "$OPTSTRING" --longoptions "$LONGOPTSTRING" -- "$@") if [ $? -gt 0 ]; then exit 192 fi eval set -- "$RESULT" while [ $# -gt 0 ]; do case "$1" in -h | --help) # show help printf "%sn" " This script helps you automate the process of downloading photos from your camera, uploading backups to Google Picasa, and syncing the files with a specified directory. Dependendies: gphoto2 dcraw googlecl rsync s3cmd usage: $SCRIPT [options] Options: -h | --help Show help for $SCRIPT --destination-directory {LOCATION} Set the location where the photos will be copied to. --tmp-dir {LOCATION} Set the temporary directory where images will be downloaded to initially. The default is /tmp/photos. --no-google-backup…
H
Hacker Public Radio

Overview I enjoy writing Bash scripts to solve various problems. In particular I have a number of scripts I use to manage the process of preparing a show for HPR, which I am developing at the moment. My more complex Bash scripts use a lot of functions to perform the various tasks, and, in the nature of things, some of these functions can be of use in other scripts and are shared between them. I thought I would share some of these functions with HPR listeners in the hopes that they might be useful. It would also be interesting to receive feedback on these functions and would be great if other Bash users contributed ideas of their own. Full Notes Since the notes explaining this subject are long, they are in a separate file which can be found here. An experimental ePub version is available by clicking this link. Links Bash Support Vim plugin: https://www.vim.org/scripts/script.php?script_id=365 HPR episode Bash parameter manipulation: https://hackerpublicradio.org/eps/hpr1648/ How to write functions (from The Linux Documentation Project): Functions: https://tldp.org/LDP/abs/html/functions.html Complex Functions and Function Complexities: https://tldp.org/LDP/abs/html/complexfunct.html Examples of functions in scripts: https://tldp.org/LDP/Bash-Beginners-Guide/html/sect_11_02.html Download the pad and yes_no functions…
H
Hacker Public Radio

Recorded using Easy Voice Recorder Pro I wrote a bash script to connect to various different windows servers from my GNU/Linux desktops. I had a few different requirements: I should be able to call it based on hostname. All windows should be 90% smaller than my screen. It should map my keyboard. It should map my local disk. It should quickly timeout if the port is not available. You can get the full script here, but let’s walk through it: The first line calls bash and then gets the server name from the symlink that is calling the script. The port is set as “3389”, but you can change that if you like. #!/bin/bash SERVER=`basename $0` PORT="3389" The next few lines finds the smallest vertical and horizontal sizes, even if you are running multiple screens. Then it calculates 90% of that to use as the size. h=$(echo "scale=0;(($(xrandr | grep '*+' | sed 's/x/ /g' | awk '{print $1}' | sort -n | head -1 )/100)*90)" | bc) v=$(echo "scale=0;(($(xrandr | grep '*+' | sed 's/x/ /g' | awk '{print $2}' | sort -n | head -1 )/100)*90)" | bc) SIZE=${h}x${v} Next we set the default username and password. I have it ask me for my password but I put it in here as an example. PASSWORD='defaultpassword' USERNAME='administrator' WORKGROUP='workgroup' In some cases the credentials may be different, so I have a case statement that will cycle through the servers and apply the differences. Depending on your naming schemes you may be able to use regular expressions here to filter out groups of servers. case "${SERVER}" in *server*) echo "Server ${SERVER}" PASSWORD='work_password' USERNAME='administrator' WORKGROUP='WORKGROUP' ;; *colo*) echo "Server ${SERVER}" PASSWORD='colo_server_password' USERNAME='administrator' WORKGROUP='COLODOMAIN' ;; some_server ) echo "Server ${SERVER}" PASSWORD='some_server_password' USERNAME='some_server_password' ;; *) echo "No match for ${SERVER}, using defaults" ;; esac Next we use an inbuilt bash command to see if a remote port is open and timeout after one second. timeout 1 bash -c "echo >/dev/tcp/${SERVER}/${PORT}" I used to connect to rdp using the program rdesktop, but it is now of limited value due to the fact that there are many open bugs that are not getting fixed. Bugs such as Bug 1075697 - rdesktop cannot connect to systems using RDP version 6 or newer and Bug 1002978 - Failed to negotiate protocol, retrying with plain RDP . I then switch to using xfreerdp. This is the client that is behind remmina. You can use xfreerdp /kbd-list to get a list of the available keyboard layouts. if [ $? -eq 0 ]; then echo "${SERVER}:${PORT} is open" xfreerdp /v:${SERVER} /size:${SIZE} /kbd-type:0x00000409 /t:${SERVER} /d:${WORKGROUP} /u:${USERNAME} /p:${PASSWORD} /a:drive,pc,/ /cert-ignore & else echo "${SERVER}:${PORT} is closed" fi Next you will need to be sure that your host names are available, either in dns or in your /etc/hosts/ file. For example: 10.1.0.1 server1 10.1.0.2 serve…
H
Hacker Public Radio

Bash parameter manipulation I'm a great fan of using the Linux command line and enjoy writing shell scripts using the Bash shell. BASH (or more usually Bash or bash) is the name of a Unix shell. The name stands for Bourne Again SHell, which is a play on words. Bash is an extension of the shell originally written by Stephen Bourne in 1978, usually known as SH. Bash was written as part of the GNU Project which forms part of the Linux Operating System. A shell is the part of the operating system that interprets commands, more commonly known as the command line. A knowledge of Bash is very helpful if you would like to be able to use the power of the command line. It is also the way to learn how to build Bash scripts for automating the tasks you need to perform. In this episode we look at what parameters are in Bash, and how they can be created and manipulated. There are many features in Bash that you can use to do this, but they are not easy to find. As I was learning my way around Bash it took me a while to find these. Once I had found them I wanted to make a "cheat sheet" I could stick on the wall to remind me how to do things. I am sharing the result of this process with you. The version of Bash which I used for this episode is 4.3.30(1)-release The full notes for this episode are to be found here: hpr1648_full_shownotes.html Links Definitions: Unix shell https://en.wikipedia.org/wiki/Unix_shell Bash https://en.wikipedia.org/wiki/Bash_%28Unix_shell%29 GNU Project https://en.wikipedia.org/wiki/GNU_Project References Shell Parameter Expansion https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html Bash Hackers on parameter expansion https://wiki.bash-hackers.org/syntax/pe Previous HPR shows on the shell or shell scripting: 2008-03-03 HPR0045: Shell Scripting (dosman) hpr0045 2008-03-12 HPR0052: UCLUG: Newbie Shell Scripting (Dave Yates) hpr0052 2010-03-24 HPR0531: bash loops (Ken Fallon) hpr0531 2010-08-11 HPR0562: Introduction to bash scripting (Ken Fallon) hpr0562 2010-11-17 HPR0598: Bash Scripting: Episode 2 Command Line Basics (Ken Fallon) hpr0598 2012-05-22 HPR0992: Linux In The Shell 007 - Chmod and Unix Permissions. (Dann) hpr0992 2012-06-05 HPR1002: Linux In The Shell 008 - free: Understanding Linux Memory Usage (Dann) hpr1002 2013-03-05 HPR1197: What I do with bash scripts (Jon Kulp) hpr1197 2013-04-09 HPR1222: LiTS 027: mathematical commands (Dann) hpr1222 2013-05-14 HPR1247: Recording T…
ברוכים הבאים אל Player FM!
Player FM סורק את האינטרנט עבור פודקאסטים באיכות גבוהה בשבילכם כדי שתהנו מהם כרגע. זה יישום הפודקאסט הטוב ביותר והוא עובד על אנדרואיד, iPhone ואינטרנט. הירשמו לסנכרון מנויים במכשירים שונים.