read

Double backslash disappears when printed in a loop

Double backslash disappears when printed in a loop I have a script that joins together various lists of data fields which then needs to have a few more columns added. The file generated looks like this: $ cat compiled.csv "name":"Network Rule 1", "description":"Network Rule 1", "from":["internal"], "source":["any"], "user":["domain\network_user1"], "to":["external"], "destination":["host.example.com","10.1.2.1"], "port":["8443","22"], "name":"Network Rule 2", "description":"Network …

Total answers: 1

Issue of read with -u and -k in zsh

Issue of read with -u and -k in zsh I am developing a zsh script that uses read -k. If I execute my script like this (echo a | myscript), it fails to get input. Apparently it is due to the fact that -k uses /dev/tty as stdin invariably, and you must tell read to …

Total answers: 1

Execute copy commands from file

Execute copy commands from file I have a DE_CopyOldToNew.txt file with a whole bunch of copy commands for copying old file names to new file names. The file contains rows like : cp /migrationfiles/Company Name GmbH/2014.138_Old File Name.pdf /appl/data/docs/202403/DE_2014.138_NewFile_1.pdf cp /migrationfiles/Company Name GmbH/2014.139_Old File Name.pdf /appl/data/docs/202403/DE_2014.139_NewFile_1.pdf In my shell script I am iterating over each …

Total answers: 3

Why does `read` fail saying "read error: 0: Resource temporarily unavailable"?

Why does `read` fail saying "read error: 0: Resource temporarily unavailable"? script #!/bin/bash — # record from microphone rec –channels 1 /tmp/rec.sox trim 0.9 band 4k noiseprof /tmp/noiseprof && # convert to mp3 sox /tmp/rec.sox –compression 0.01 /tmp/rec.mp3 trim 0 -0.1 && # play recording to test for noise play /tmp/rec.mp3 && printf "nRemove noise? …

Total answers: 1

pipe the read command?

pipe the read command? I’m trying to pipe a string with special characters (e.g. HG@eg3,l'{TT"C! to another command (termux-clipboard-set) with the read program. It seems that read was designed to create a temporary variable (e.g. read temp) that should be then passed to another command (e.g. termux-clipboard-set $temp). I’m wondering if there is a faster …

Total answers: 2

Store multiline output in separate variable

Store multiline output in separate variable A script outputs 3 line output: $ Filename /a/Resource/.Filename.man.markdown .Filename.man.markdown .Filename man.markdown What I want to do I want to store the 3 line output in separate variable, how can I do it? I tried the following – Why it fails and how to do it correctly? 1st failed …

Total answers: 1

"read -r" builtin in bash script acts differently on Mac

"read -r" builtin in bash script acts differently on Mac I have this script: #!/bin/bash function main { while read -r file; do do_something "$file" done <<< $(find . -type f 2>/dev/null) } function do_something{ echo file:$@ } On linux, it works fine, but on Mac (Bash version 5.2), it treats all files found as …

Total answers: 1

Why is my entire home backed up?

Why is my entire home backed up? I wish to back up some of the files located in my home dir. That is simple files at the root of my home and some directories in my home, listed in ~/worthsaving.txt Sample worthsaving.txt: cloud work/web work/python I made this script : #!/bin/bash srce=/home/poor dest=/run/media/poor/backup mkdir -p …

Total answers: 1

How does "done < file" work in a while loop?

How does "done < file" work in a while loop? While trying to learn how to manipulate the content of files in bash, I encountered the following code example: while IFS=, read -r col1 col2 do echo "I got:$col1|$col2" done < myfile.csv According to The Open Group Base Specifications Issue 6: The read utility shall …

Total answers: 1

How to capture subshell exit code when assigning subshell output to read?

How to capture subshell exit code when assigning subshell output to read? Consider: $ read -r a <<<$(echo "foo"; exit 1) $ echo $? 0 this returns 0, when I really expect a 1. How can I extract the real exit code from the subshell? Asked By: Foo || Source You’ll need multiple steps: output=$(echo …

Total answers: 1

How to read multiline input in bash

How to read multiline input in bash I have this script: #!/usr/bin/env bash main() { while true; do read -r -ep "> " input history -s "$input" echo "$input" done } main which works well for single line strings. Now I’m looking to allow the user to enter multiline strings, e.g. something like the following: …

Total answers: 1

Specify a Keypress as a variable for "if" command

Specify a Keypress as a variable for "if" command Before continuing, please bear in mind that I am aware that I could configure keyboard shortcuts through the settings menu, but that would not be of use for my end goal. I’m trying to create a simple script to take a single keypress as the input, …

Total answers: 1

Bash variable truncated when passed into ffmpeg

Bash variable truncated when passed into ffmpeg I have an album of 11 .flac audio files. (edit: since this issue has been resolved, it’s now clear that the precise names and content of the files are irrelevant, so I’ve renamed them): > find . -name "*.flac" ./two.flac ./ten.flac ./nine.flac ./eight.flac ./seven.flac ./three.flac ./four.flac ./five.flac ./one.flac …

Total answers: 1

Why does the execution of these functions break out of this while loop?

Why does the execution of these functions break out of this while loop? The following script is meant to trim all media files in the current working directory. #!/usr/bin/bash trimmer() { of=$(echo "${if}"|sed -E "s/(.)([avimp4kvweb]{3,3}$)/1trimmed.2/") ffmpeg -hide_banner -loglevel warning -ss "${b}" -to "${ddecreased}" -i "${if}" -c copy "${of}" echo "Success. Exiting .." } get_ddecreased() { …

Total answers: 1

How to "properly" read remote sshd server version with bash

How to "properly" read remote sshd server version with bash I’m trying to read remote SSHD server version with bash without installing an extra tool : $ cat < /dev/tcp/x.y.z.t/22 SSH-2.0-OpenSSH_7.2 FreeBSD-20160310 ^C CTRL+C is needed, so I tried to read only one line but something strange happens in the output : $ read version …

Total answers: 1

Trying to find complete string values from one file based on another file using AWK

Trying to find complete string values from one file based on another file using AWK Hello I have 2 files with the first file containing a few values for example powershell vectormaps JuniperSA and the second file containing values and and ID appid uid SplunkforSnort 340 powershell 610 vectormaps 729 JuniperSA 826 postfix 933 SplunkforJuniperSRX …

Total answers: 3