Questions tagged [bash]

Questions specific to GNU’s Bourne Again SHell, as opposed to other Bourne/POSIX shells. For questions about Unix shells in general, use the /shell tag instead.

Filter by
Sorted by
Tagged with
0
votes
1answer
16 views

problem escaping quotes in script

I'm constructing a command line for use with the 'mogrify' tool [part of imagemagick]. the finalised command line looks something like this : mogrify -stroke yellow -draw 'line 0,0 0,319' -draw 'line ...
0
votes
0answers
9 views

su -c no such file or directory on Android 9 aarch64

I have a rooted android phone use Lineage OS 16 (based on android 9). Architecture is 64 bit. I need to code a "su -c" before the following: /data/data/com.mytestapp/APPS/bin/bash But the output was:...
-1
votes
1answer
26 views

Bash ANSI C quoting not correctly quoting newlines

ANSI C Quoting in bash is supposed to read strings the same way C(or python with single quotes) would. printf $'"Hello, World!\\n"' #expected output (no newline, the slash is escaped) "Hello, World!...
0
votes
1answer
8 views

How to run lxc exec for commands with pipe?

for example, I have this command: lxc launch ubuntu:18.04 memsql1 lxc exec memsql1 -- wget -O - 'https://release.memsql.com/release-aug2018.gpg' 2>/dev/null | sudo apt-key add - && apt-...
0
votes
1answer
23 views

How Difficult to Move From Debian Distros to Manjaro?

I consider myself a somewhat beginner-intermediate level user , with my experience having been primarily in Elementary OS, Mint and Ubuntu, in that order of preference as of now. Most of my activities ...
-1
votes
1answer
38 views

syntax for using head with filename stored in variable

I'm trying to store the first 5 lines from a file in the variable url. But I get an error -n5: command not found fn_all_urls stores the path to the file /home/urls.txt My Line is: url=head -n5 ${...
0
votes
0answers
28 views

How to use sed to replace variable value with a variable of the same name?

I'm trying to write a script that updates a server config file to the latest format. The purpose of the script is to copy over existing (defined) variables to the latest config (in a temp file), then ...
0
votes
2answers
32 views

Directory stack (pushd and popd) behaviour in bash scripts

If I poorly write a script that uses pushd /etc but I don't finish it with popd: Will /etc still be in the pushd+popd directory stack/in RAM after the bash script has finished executing and Bash has ...
1
vote
0answers
31 views

How to can I cause an exit, from a script that receives data through a pipe, from another program?

I have Bash script that is used to process data, which is sent through a pipe from another process. I'm trying to add a functionality that causes and exits after a certain condition is met, whose ...
-1
votes
2answers
36 views

copy multiple lines and past in the end of another text file

I have a bash script, which shows some flag (some text) on terminal at the end of the execution. I want to copy these flags (text) in the end of another file. I want to copy these flag (after the ...
-1
votes
1answer
30 views

How can I check a field in a CSV file using Linux tools?

I would like to accomplish the following using Linux bash and/or Linux utilities. I'm running Debian 10 on a cloud server. I have a csv file of the following form: "2019-12-10_15-03-50",13,"...
3
votes
1answer
35 views

What's the difference between `-h` and `-L` in bash conditional expressions?

According to the man page: -h file True if file exists and is a symbolic link. ... -L file True if file exists and is a symbolic link. They both seem to ...
-4
votes
2answers
50 views

Shell Script - Alphabet in code

I want to create an alphabet where each letter and character has a specific value. Example: A="99_banana" a="@_melon" B="22_GRAPE" b="orange" C="Strawberry" c="life" @="12399" !="tv_12" and so on ...
1
vote
0answers
42 views

How to trigger a prompt redraw when the terminal window size changes?

So I created a trap to check if the change is being registered: trap 'echo $COLUMNS' WINCH And the change is indeed reflected. But my prompt is not redrawn, neither from re-issuing the $...
1
vote
2answers
45 views

Changing a file with values from another file - Bash script

I am trying to write a script that takes two files as arguments and changes an .svg file with values from a .csv file. Csv file consists of lines with two values; id,colour. I need to find the id in ...
0
votes
1answer
53 views

Pass bash variable into python file

I have a Python script that I want to pass a bash variable to. bash.sh while read -r db do Printf "%s\n" ${db} "Found" done < path/to/file.txt output: db1 db2 db3 file.txt ...
0
votes
1answer
24 views

How to prepend value to the cat command output without modifying a file?

At work, there is a custom script that I must use to apply a SQL script to a mysql database server and have no liberty to modify. The command line options of the custom script is very limited. For ...
9
votes
4answers
520 views

Bash globbing that matches all files except those with a specific extension, that works on filenames that include dot characters

I'm doing some stuff with audio files, most but not all of which are mp3 files. Now I want to run some commands on only the files which are not mp3 files, or only those which don't have a .mp3 ...
0
votes
0answers
46 views

Is it guaranteed freshly opened `/dev/fd/3` always reads from start?

This is a Linux-specific question. The bash script is: echo foo > "a.txt" exec 3<"a.txt" cat /dev/fd/3 cat /dev/fd/3 cat /dev/fd/3 Output: foo foo foo All these cats display the content of /...
0
votes
0answers
36 views

Why is “&” necessary to make a Unix fork bomb work? [duplicate]

Consider the canonical example of a Unix fork bomb: DANGER: running the following command, might crash your system. :(){ :|: & };: I wonder why & (background) is needed in order to use up ...
1
vote
2answers
21 views

Is is possible to iterate through a series of letters and numbers longer than one character in a linux loop?

In Linux is it possible to iterate through a series of letters or numbers more in a length of more than one? Ex: AAA,AAB...ZZY,ZZZ or 000...999, keeping the zeros in place I understand that you can ...
0
votes
1answer
26 views

How to exit true from a heredoc command from MYSQL?

I have a script that exits on error using set -e and I can't figure out how to force it to return true despite || true #!/bin/bash mysql -h localhost -D test -ppassword <<-RENAME ...
0
votes
1answer
22 views

Setting PS1 on macOS Catalina causes Terminal prompt to overlap itself when window is resized

I've set PS1 in my .bash_profile, and while the colors work I get awful word wrapping and weird line behavior when I resize my Terminal window size. Here is my .bash_profile: [[ -s ~/.bashrc ]] &...
5
votes
3answers
741 views

Filter 500 files with awk, then cat results to single file

I'm in a directory with a couple thousand files, but the files I want to filter all have the following syntax: *.imputed.*_info I want to use awk to filter out the records in each file where the 5th ...
-1
votes
1answer
32 views

IF loop with multiple OR condition throwing syntax error

I want to add multiple or condition where I am comparing string values, with single string value my following code is working prname ="$projname" if prname == 'CheckForUpdate': ...
3
votes
3answers
78 views

bash: race condition with pipeline, tee and process substitution

I want to see twice being output twice, but this script will only output it once: dump() { (sleep 1; cat) > "$1" } (sleep 0; echo "twice") | tee >(dump "./a.txt") echo "$(< "a.txt")" To ...
4
votes
1answer
24 views

bash: use different input streams for loop condition and body

i have a script with a while loop like this: while IFS= read -r name; do {body} done < names.txt the loop condition needs to read names from a file, but {body} needs to read from stdin; the ...
0
votes
1answer
24 views

What could cause a log file to be trunctated during writing?

In my workplace, I've inherited the responsibility of managing a web server. It's a CentOS Linux virtual machine, running on Amazon AWS EC2. Alongside serving web pages, there is a pile of scheduled ...
0
votes
1answer
58 views

Is there a way to overwrite pipe on linux bash?

I was wondering if there is a way to replace the default behavior of the | command in bash with a custom command. I would like overwrite the pipe command. This is a strictly technical and ...
0
votes
0answers
17 views

How to set DTR of COM high using Bash script without using C code?

I've purchased a HMI running on Linux. This HMI has a serial port and I'm trying to set the DTR signal of this port. However this Linux is stripped down and I cant install a C compiler etc. I'm trying ...
0
votes
0answers
13 views

Alias for a compound bash command with subcommands [duplicate]

I want to create an alias for a command to stop and remove all containers: docker stop $(docker ps -aq) && docker rm $(docker ps -aq) When I just paste this command in my command line, it ...
1
vote
1answer
52 views

How can a command within a pipeline abort the pipeline?

Given the pipeline a | b | c how might I alter b so that it aborts the pipeline if b generates an error or matches a particular pattern in the input stream?
1
vote
0answers
33 views

How to make a simple menu in bash from an associative array

I am refactoring a script that displays a text menu similar to this: Select a mounted BTRFS device on your local machine to backup to. 1) 123456789abc-def012345-6789abcdef012 (/) 2) 123456789abc-...
1
vote
2answers
63 views

How to update values in a csv file with values from another csv file, using bash

I have two files, each with data arranged in two columns. Columns are separated by a semicolon. The first file (11_19.txt) includes more lines and the second file(12_19.txt) is to update the first ...
-4
votes
3answers
40 views

Shell: How to get number from file?

1 2 5 7 I have numbers like this in a text file. How can I print the third number using a shell script?
0
votes
1answer
51 views

I need to ssh into another machine using expect and a password and start a program there, then start a program on my local machine. How can I do this?

As said in the title, I am writing a script that should run on Computer A. Computer A should ssh on Computer B, run Program B, then exit the ssh session (Program B still running on Computer B) and ...
1
vote
0answers
23 views

Recall nth word from previous command that used brace expansion

I frequently find myself copying an existing file before editing it. I'm quite lazy, so of course I make use of brace expansion: $ cp some/long/path/to/file{a,b}.txt $ vi some/long/path/to/fileb.txt ...
0
votes
0answers
14 views

Finding files not including and index page and copying one over [closed]

I have a pre-existing code that works for doing this in all directories including children but I need to reuse it for a depth of 1. What am I missing in the following code? find /tv/ -maxdepth 1 -...
0
votes
2answers
31 views

How to Get user input from the stdout of for loop index

Here is the shell script I want to execute. for example, I have 100 kubernetes pods with 100 different vehicles. I want a list to be generated of cars and choose 10 particular cars from the list. ...
-2
votes
0answers
31 views

What does the s in the permission bits mean from ls -l? [duplicate]

When I type in ls -l, I get the following output in the permission bits: -rwsr-sr-x I am somewhat confused as to what do the two 's' mean? Is the 's' a permission for an entity?
0
votes
1answer
15 views

How to create a bashrc/zshrc symlink?

I reinstall my OS a lot, and I've learned to start backing up configs in iCloud Drive folder The command I generally run (after searching google for the nth time): ln -s "/Users/myName/Library/...
1
vote
2answers
30 views

Completely Clear Bash History From Shell Script (sysprep)

I'm working on a sysprep-style script which de-identifies a machine and gets it ready for templatizing. The last task that I'd like to perform (before shutdown) is clearing the bash history for the ...
-1
votes
0answers
24 views

How to transfer files inside NAS server with “scp” and print a progress bar and total time transfer. WITHOUT USING RYSNC

Hello I would like to use scp inside a bash script that go from local to remote and copy files and display the progress bar and total time of download. I used rysnc but is not good for me because is ...
0
votes
1answer
25 views

read pipe input from keyboard

This is very basic, sorry if this is a duplicate, but search results give me something opposite. I want to paste lines as an input to a pipe. How can I do it? For example I want to use this answer ...
0
votes
1answer
49 views

basename command is not working in jenkins [closed]

Created one jenkins parameterized job. where userspecificlocation --> full path of the file. ssh ubuntu@$ip -n "aws s3 cp s3://bucket/$userlistlocation . --region eu-central-1" fbname=`basename $...
-1
votes
1answer
48 views

Add extensions to the end of files [closed]

I have an assignment in which I have to create a script which accepts a directory and then takes the files in the directory and adds .old if not already added. I have wrote a script but it keeps ...
-4
votes
1answer
41 views

how to create the automate username and password in bash script in centos [closed]

Hi everyone i am wondering if anyone could help me for bash script in centos to making 4 groups and adding about 10 user with password to each groups, considering the password should be automated for ...
0
votes
1answer
33 views

Use columns in a file as output file variable names

head testregions.bed 21 15390708 21 15890068 16388793 21 16390041 16888505 21 16889055 17388185 21 17388731 17886839 I wanted to use each ...
-1
votes
0answers
45 views

What could be the reason for “Argument list too long: /bin/bash” error, while executing encrypted bash file?

I have written a bash script which is of size around 500 kB and encrypted it following this guide https://www.thegeekstuff.com/2012/05/encrypt-bash-shell-script/ The problem is when, I execute ...
0
votes
1answer
18 views

Are subshells run in parallel by default?

This question follows from this one and one of its answers' recommendation to read Linuxtopia - Chapter 20. Subshells. I'm a bit confused by this statement at the Linuxtopia site: subshells let ...