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. For shell scripts with errors/syntax errors, please check them with the shellcheck program (or in the web shellcheck server at https://shellcheck.net) before posting here.

Filter by
Sorted by
Tagged with
0
votes
0answers
10 views

STATA tab command as a linux command

STATA has a command tab that lets me input a csv and a column name. It will summarize the results of the column like so: . tab officer_gender Officer | Binary-Gend | er | Freq. ...
0
votes
0answers
5 views

I'm trying to execute a fifo list to enable vm manager in gcp

so the command goes something like this. gcloud compute project-info add-metadata --project projectname --metadata=enable-guest-attributes=TRUE,enable-osconfig=TRUE I'd like to run a command that ...
1
vote
1answer
31 views

/etc/bash.bashrc equivalent for sh

I know about the differences between ~/.bashrc, ~/.bash_profile, /etc/profile, and /etc/bash.bashrc. Other than /etc/profile, these are all specific to the bash shell. I would like to have a script ...
0
votes
2answers
41 views

How to load more than 10 files with range in executable args?

I have this working command line expression: program --files path_to_mydir/mydata_[0-9].csv I would like to go from [0-100] but this is not working. program --files path_to_mydir/mydata_[0-100].csv ...
0
votes
0answers
17 views

Removing malformed elements in XML file using bash script

I have been querying large numbers of records from a database which returns the records in XML format. Occasionally, query errors will cause malformed records to be written which take the form of ...
0
votes
1answer
41 views

How to run “for loop” in a list of hosts from a hop server using for or any loop?

Want to run "for loop" from a hop server to a list of servers. If I run the for loop in individual server, it works fine but I don't know how to nest it and make it work from a hop server. ...
0
votes
3answers
36 views

Echo array on newlines with index numbers

I'm trying to echo all elements of an array on a newline and also with an index number next to it. So that I can take some input and then select an array element to open with a text editor. (they're ...
0
votes
1answer
59 views

Reordering a name file in linux/ubuntu

I'm trying for a time now to have the titles of some(1 to 3 hundred) musics changed, using bash script or commands like rename or sed, along with regex, but I failed miserably, probably because I'm ...
0
votes
0answers
33 views

convert -crop only splits part of png

i want to write a bash script, that concatenates some images into one and then splits that one into images of the same size. It works for the most part. My testimages give me a png file that's ...
0
votes
4answers
47 views

reading and discarding lines

I have a question about a problem that I have to solve, I have my lines in this way: Input GTEX-1117F-0003-SM-58Q7G GTEX-1117F-0003-SM-5DWSB GTEX-111CU-0826-SM-5EGIJ GTEX-111CU-0926-SM-5EGIK GTEX-ZZPU-...
1
vote
1answer
36 views

How to display only shell variables (not functions) [duplicate]

How can I display a list of shell variables in Bash, not including functions, which often clutter the output, because of the many related to completion? I have examined declare, and it has an option ...
6
votes
1answer
624 views

How to make a multiline alias in Bash?

I want to make an alias for a multiline ​command to call it faster then copying-pasting-executing it from a text file each time. An example for such command is this execute-a-remote-updater command: ( ...
2
votes
1answer
86 views

How can SQLite command “.import” read directly from standard input?

How would you modify function csv_to_sqlite so that sqlite3 command .import reads directly from standard input instead of from a temporary named pipe? #!/bin/bash function csv_to_sqlite() { local ...
0
votes
1answer
22 views

How to echo an exclamation point without the backslash in the output to prevent expansion

I usually like to echo certain string which have an exclamation point in them. And while i know how to escape them to prevent expansion by the Shell, i noticed it also print the backslash... echo &...
0
votes
1answer
57 views

How does the {,string} syntax work?

I have some hard time understanding the {,string} syntax. I mainly use it to rename a files like mv test{,.original} But I don't really understand it: echo asdf{,.fdsa} Output: asdf asdf.fdsa But ...
1
vote
0answers
44 views

echo hashed password for sudo command in multi system

I want to make a shell that sends command which runs at sudo level, from a system to multiple system. for example: for system in ${systems[@]}; do ssh $system "echo 'password' | sudo -S yum -...
4
votes
1answer
76 views

Heredoc in subfunction in exported function fails

This works: #!/bin/bash foo() { gen() { cat <<EOF bar EOF true } gen } foo export -f foo bash -c foo This fails in the very last line: #!/bin/bash foo() { gen(...
0
votes
0answers
33 views

A custom bash daemon progressively eating memory

Hello I've written a keep-alive daemon that when run, spawns json-server and respawns json-server if its process is killed. #!/usr/bin/bash function start () { trap 'echo "Clean up and exit&...
-3
votes
1answer
59 views

2 decimal increment in seq makes everything with 2 decimal

I want to use this command in bash: datarange=$(seq 0.5 0.25 5.5) with output echo $datarange = 0.50 0.75 1.00 1.25 1.50 1.75 2.00 2.25 2.50 2.75 3.00 3.25 3.50 3.75 4.00 4.25 4.50 4.75 5.00 5.25 5....
0
votes
1answer
37 views

xkb Can't find file “myswap” for symbols include error in systemd python job

I'm using Ubuntu 20.10 and python 2.7. I've got a bash script which overwrites default keyboard bindings and it always works when I execute it from terminal, here's the script. #!/bin/bash xkbcomp -...
1
vote
1answer
41 views

Using alternation when matching filename globbing pattern

if [[ $1 == *.(png|jpg) ]] is what I've tried, and it doesn't work. I need to check if $1 matches one of those filename suffixes, so I can then do stuff with it. I'm not sure how to go about this. I'...
0
votes
1answer
28 views

Prevent expect from hanging when running through ssh

Based on another post's answer, i managed to make expect automate vncserver through ssh (optionally on a chroot in this case), like so: ssh user@ip "rm ~/.vnc/passwd" echo -n "`PASS_VNC`...
1
vote
2answers
63 views

Run bash without user config while still able to set bindings

I would like to be able to run a script with the following two properties Everything inside the script is run as if the bashrc was never sourced. I can still set bindings that will remain after the ...
5
votes
4answers
237 views

bash - get 1st argument of current command I am editing via history, or similar? [duplicate]

Often I'm writing a command in a bash prompt, where I want to get previous arguments, in the CURRENT line I'm typing out, and put in other places in the command. A simple example, would be if I want ...
0
votes
1answer
57 views

How to read my file correctly?

I have a question about how to read my file correctly in UNIX, I have the file given (attached as image) and this file has tabs between the variables, as you can see Blood is a variable and Whole ...
3
votes
3answers
106 views

Find and print the length of the longest line in multiple files?

In my folder, I have 2000 files, which are labeled A0001-A2000. In the second line of each file, there is a long (it should be the longest) line of characters. I would like to print all the file names ...
0
votes
0answers
23 views

Make API requests recursively without large number of processes running

I have the following Script File 'bored.sh'. This file recursively calls itself. curl "https://www.boredapi.com/api/activity" >>./bored.json sleep 1s bash ./bored.sh I realized that ...
0
votes
1answer
44 views

Command not found when executing in remote server using shell script

I am trying to automate a few steps that I need to execute in a remote linux machine from my local ubuntu computer. My shell script is as follows :- #!/bin/sh ssh XYZ ' qlogin -l cuda=1 ' When I ...
0
votes
1answer
34 views

egrep matching lines that shouldn't match

I am trying to find out if any of the floats in the first column containing floats in a CSV have a 1 after the decimal point. Here is an example row from my CSV: 1082805252197942751,34225793738713276,...
1
vote
2answers
56 views

Run thousands of simple scripts in parallel

I would like to run a simple python script in ~6500 directories. The easiest, and least efficient way is to do: for d in *_directorynumber; do (cd "$d" && cp ../script.py . &&...
0
votes
0answers
28 views

Check if script completed successfully or not

I have 10 scripts that runs sequentially as a part of daily overnight batch. The 6th last script marks the completion of batch. Instead of manually checking the timings of that run, I'm trying to ...
1
vote
2answers
52 views

starting a background job on the remote host over ssh hangs the calling script

I have this code : for i in $ipb $ipc $ipd; do ssh -i ~/.ssh/'key' 'name'@${i} /bin/bash << EOF nohup ${install_dir}/redis-stable/src/redis-server ${install_dir}/${port}/node.conf & ...
0
votes
0answers
15 views

Enforcing native Python3 to show up when I enter Python in CentOS 7

I have installed both native Python 3 and Anaconda Python 3 however, at the moment, I want to use native Python 3 when I enter $ python. Do you know why it defaults to Anaconda Python 3 and how can I ...
1
vote
2answers
50 views

How to append the begining of a file with text from STDIN

I'm working to debug some kind of issue with the Nix Linux installer script on Debian-based OSs Like what was said here, this snippet of the /etc/bash.bashrc: # If not running interactively, don't do ...
0
votes
1answer
59 views

How to match a string on a file using pure bash?

So i want to match a string/or word on a file, but without using any external tools (grep, sed etc), with only pure bash... Essentially i want the equivalent of: grep "string" file or grep -...
-1
votes
0answers
40 views

Extracting data from multi line field value pairs

I have a file containing file value pairs in multiple lines. Line: 1 Field name1: Value1 Field name2: Value2 Field name3: Value3 Line: 2 Field name1: Value1 Field name2: Value2 Field name3: Value3 ...
1
vote
1answer
36 views

How does bash work on different operating systems?

How can the bash shell work in many different systems like "gnu/linux" "unix" and "freebsd" etc.? Since the kernels of these systems are different, how can bash perform ...
0
votes
0answers
35 views

How do I create text file and file name contains the creation date in bash?

I need a bash script for new text files generation in a folder with an interval of a few seconds and stops after a specified time. The content does not matter, the filename should contain the creation ...
2
votes
1answer
109 views

Prevent command substitution from running when declaring a variable

So i recently noticed that, when declaring a variable using a command substitution, let's say like so: var=$(echo "this is running" > test; cat test) Then it will run (the file test will ...
1
vote
4answers
167 views

Grep number behind path, tab and space in a string

Given a string s s="B /home/BL/004_010_0100.0 23 0.031" How can I grep only the number behind the path, tab and space in a string? In the string s above, I'd like to extract the ...
0
votes
2answers
38 views

Get logs for specific date (apache access log)

Can you on advice me on how to get specific time range from a file with output like: 81.200.176.13 - - [23/Mar/2021:09:34:03 +0000] "GET /crx/packmgr/img/thumbnail.png HTTP/1.1" 200 6235 I ...
0
votes
1answer
17 views

How can I make registered extensions for `binfmt_misc` persist across reboots?

How can I make registered extensions for binfmt_misc persist across reboots? Consider the following command, which performs a binfmt_misc registration: echo ':golang:E::go::/tmp/test:OC' | sudo tee /...
2
votes
1answer
42 views

Initialize several bash variables with the output of a single command

My goal is to initialize multiple bash variables from the output of one single command. Specifically, line i should be the value of variable i. Example: My command is a Python program with the name ...
0
votes
2answers
25 views

Change filename of multiple files at once in linux using single command

I have multiple files and want to add a character at the beginning of filename, add extension, and remove a word in the center of the filename at once using single command and I run this using bash. ...
0
votes
1answer
46 views

How to implement search similar to 'apt search' in bash

I'm writing a bash script that is a "package manager" that uses pi-apps. I want to implement a search function so I can search apps. right now what I'm doing is this (template is a folder I ...
1
vote
1answer
33 views

Interactive Fortran Program

I have an old fortran executable foo.exe that requires interactive input. If I call foo.exe from Cywin I am prompted for the interactive input and the program works fine. If I call foo.exe from WSL I ...
-1
votes
1answer
27 views

Using shell arrays to read every N lines in parallel of a file

So, i already know how to successfully read every N lines in parallel, and run a command on each of those lines: while read -r i && read -r a && read -r b && read -r c &&...
1
vote
1answer
32 views

Difference between “IGNOREEOF=n” variable and “ignoreeof=n” word usage?

When i use ignoreeof of set builtin, i realized "IGNOREEOF=n" variable and "ignoreeof=n" word can usable for limitation. For example; └─$ bash └─$ set -o ignoreeof └─$ IGNOREEOF=2 └...
0
votes
1answer
23 views

Dpkg/atop daemon error

Whenever I try to install any package the following error occurs after a small bit of working normal: penguin systemd[1]: atopacct.service: Failed with result 'protocol'. penguin systemd[1]: Failed to ...
0
votes
1answer
32 views

Why does a command not work as alias? [duplicate]

Using the command directly works: $ find \ /home... But not as alias: alias synclinks="find \ /home/foo/Pictures/ \ -type f -exec file --mime-type {} \+ | \ awk -F: '{if ($2 ...