Posts tagged shell-scripting
I'm trying to create a .desktop file which opens a file, either inside a Vim server named "VIM" if it exists, or otherwise using the normal Vim .desktop file. This is what I have so far: [Desktop...
I came across this in a bash script: excludes+=("${2-}") What is the meaning of ${2-}?
Online, I often see someone tell people to run a command like /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" (example from https://brew.sh/). The g...
I have long been in the process of converting my manual steps to create a new backup disks into an automated script. The only part I have left is the initial "creation" of the disk, meaning whateve...
How to apply a logical not to a shell command, e.g. in a Bash script? So if the command exited with 0 (success) I would like it to be changed to a non-zero value, and if it exited with a non-zero ...
Suppose I have a list of files on standard input. These may be the output of find, cat filelist.txt or something else. How can I run a command on each file in turn?
How can a file list be manually filtered with a gitignore file. I want to do the equivalent of git ls-files, but it should work even if I remove .git, so I can't use git(1). Currently, I'm doing ...
I'm trying to run a pipeline to update a PDF after every push to the 'main' branch. I want it to be atomic, so it doesn't touch the existing PDF until it has finished, so I need to use sponge(1) (...
Sorry it was a typo, _ instead of -, that caused the problem. I want to have a key combination to alter the keymaps. It worked with one for us and one for hu, but now I want to use one key combina...
Say I have some Bash function my-func, that expects a filename and does some processing on the corresponding file. For demonstration purposes, my-func() { cat "$1"; } If I want to apply that fu...
I want the cd command to automatically change to the first directory that matches a fuzzy search, without prompting me to select between multiple options. This is what I've tried: cd() { loc...
Suppose I have a command that takes filenames as arguments, like: diff foo.txt bar.txt What if instead of actual files, I want to use the results of a command in each? I can use temporary files: ...
I have a shell script with a syntax compatible to both bash and zsh, except for a section that has zsh specific syntax that throws syntax errors if sourced from bash. Is there an easy way to escap...
I have a handful of shell scripts that accept any number of command line arguments, then do some relatively expensive processing based on each command line argument in turn. The general format for ...