https://linux.codidact.com/categories/60/tags/5892.rssNew Posts Tagged 'shell-scripting' - Linux SystemsLinux Systems - Codidact2024-03-26T14:41:22Zhttps://linux.codidact.com/posts/288310How to run a command on a list of files?matthewsnyderhttps://linux.codidact.com/users/613082023-06-11T23:19:02Z2024-03-26T14:41:22Z<p>Suppose I have a list of files on standard input. These may be the output of <code>find</code>, <code>cat filelist.txt</code> or something else.</p>
<p>How can I run a command on each file in t...https://linux.codidact.com/posts/290162How to invert command exit code?Iizukihttps://linux.codidact.com/users/649262023-11-03T08:23:13Z2024-03-19T11:40:28Z<p>How to apply a logical <em>not</em> to a shell command, e.g. in a Bash script?</p>
<p>So if the command exited with 0 (success) I would like it to be changed to a non-zero value, and if it exit...https://linux.codidact.com/posts/290836How to use the gitignore file without git(1).alxhttps://linux.codidact.com/users/539372024-02-16T21:34:53Z2024-02-16T22:24:19Z<p>How can a file list be manually filtered with a gitignore file.</p>
<p>I want to do the equivalent of <code>git ls-files</code>, but it should work even if I remove <code>.git</code>, so I can'...https://linux.codidact.com/posts/290283Run pipeline in the background from git hookalxhttps://linux.codidact.com/users/539372023-11-24T16:48:34Z2023-11-26T09:53:04Z<p>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...https://linux.codidact.com/posts/290193Alternating 2 keyboard layouts with Key CombinationArpad Horvathhttps://linux.codidact.com/users/659632023-11-09T14:22:04Z2023-11-10T11:28:15Z<p><strong>Sorry it was a typo, _ instead of -, that caused the problem.</strong></p>
<p>I want to have a key combination to alter the keymaps. It worked with one for us and one for hu, but now I ...https://linux.codidact.com/posts/289792Higher-order functions in Bash?Karl Knechtelhttps://linux.codidact.com/users/646562023-09-23T09:36:44Z2023-09-23T16:34:57Z<p>Say I have some Bash function <code>my-func</code>, that expects a filename and does some processing on the corresponding file. For demonstration purposes,</p>
<pre><code>my-func() { cat "$1"; ...https://linux.codidact.com/posts/287901How to automatically change to the first matching directory using fuzzy search and cd?ShadowsRangerhttps://linux.codidact.com/users/580872023-02-15T18:56:26Z2023-06-16T00:38:05Z<p>I want the <code>cd</code> command to automatically change to the first directory that matches a fuzzy search, without prompting me to select between multiple options.</p>
<p>This is what I've ...https://linux.codidact.com/posts/288328When a command takes filenames as argument, how can I avoid creating temporary files?matthewsnyderhttps://linux.codidact.com/users/613082023-06-12T01:30:44Z2023-06-13T08:35:28Z<p>Suppose I have a command that takes filenames as arguments, like: <code>diff foo.txt bar.txt</code></p>
<p>What if instead of actual files, I want to use the results of a command in each?</p>
...https://linux.codidact.com/posts/285278A shell script that can run under different shells4015.althttps://linux.codidact.com/users/547322021-12-16T15:54:09Z2022-03-18T18:09:53Z<p>I have a shell script with a syntax compatible to both <code>bash</code> and <code>zsh</code>, except for a section that has zsh specific syntax that throws syntax errors if sourced from bash.
...https://linux.codidact.com/posts/284387In a bash shell script, how to filter the command line argument list to unique entries only, for processing each?Caninahttps://linux.codidact.com/users/80492021-09-28T13:56:43Z2021-09-29T13:26:06Z<p>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 f...