2022 Developer Survey is open! Take survey.

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
1 answer
37 views

looping through filename [closed]

I need to use a function that has as input multiple files. These files are related by the filename (e.g. dog1_animal.txt, dog2_animal.txt, dog3_animal.txt, cat1_animal.txt, cat2_animal.txt, ...
user avatar
  • 1
1 vote
1 answer
44 views

Why is the bash double star (globstar) operator often disabled by default?

It seems to be a very useful feature. But I had to learn that it is often disabled by default. I though about enabling it on my system. But there is probably a good reason why it is disabled. Without ...
user avatar
0 votes
1 answer
70 views

What does the "+x" option in "bash +x script.sh" mean?

I know what bash -x does, but what does bash +x do? Googling found no results and the manual also says nothing about it.
user avatar
0 votes
0 answers
43 views

Systemd service not running

I modified this script to help me continuously sync a folder to a remote using rclone. The code for said script is posted below. My issue is that on first run, it seemed to be syncing properly, only I ...
user avatar
  • 101
4 votes
1 answer
274 views

How to unset an invalid environment variable in bash?

I'm trying to add functionality to an existing docker-entrypoint script, the creators of the image decided environment variables would have the form key.subkey=value. I didn't know it was an invalid ...
user avatar
0 votes
3 answers
66 views

bash insert backslash for every slash in string

I have a string that is a path: /tmp/something I need to escape the forward slashes with backslashes: \/tmp\/something How can I do this? Maybe sed? Please point me in the right direction.
user avatar
0 votes
1 answer
42 views

Is it possible to multiple login on the same server with wget?

The aim is to enter different accounts at the same time. With lynx this is possible using files for each account with the -cfg=~/file argument. wget has a .wgetrc file that can be configured with: ...
user avatar
0 votes
1 answer
35 views

trying to add X hours to an arbitrary date in bash

Given a date string like this: 2022-03-28T23:40:49.721Z I am trying to add X hours. the function would look similar to addHours() { dateString=$1 hours=$2 return date -d 'dateString + $...
user avatar
0 votes
1 answer
46 views

How to expand tab-completion for environment variables in bash?

I have an environment variable stored in my .bash_profile called $MODULES: MODULES='/var/www/html/sites/all/modules/ When I am at the bash prompt and I type cp $MOD and then press TAB to complete, ...
user avatar
  • 123
0 votes
2 answers
29 views

How to keep my third column straight if my second one changes

I have this output from a command. CPU_SrcID#0_MC#0_Chan#0_DIMM#0 0 0 A1 CPU_SrcID#0_MC#0_Chan#1_DIMM#0 0 0 A2 CPU_SrcID#0_MC#0_Chan#2_DIMM#0 0 0 A3 CPU_SrcID#0_MC#1_Chan#0_DIMM#0 ...
user avatar
2 votes
2 answers
68 views

Filtering file list to show only files alphabetically after certain file

I have a huge number of images from which I'd like to feed some to ffmpeg time to time. But I only want to feed ones that are alphabetically after certain image (last frame of previous run, name ...
user avatar
  • 23
0 votes
2 answers
23 views

Echo choices to Choice Menu to run program directly from CommandLine

When I run a specific program with choices Do this Do that Do something else And eventual sub-choices Enter website: Enter credentials: I want to do the following echo {choice} | echo {choice2} | ...
user avatar
-1 votes
1 answer
18 views

xargs -I# showing unexpected behavior - why?

I'd like to zip a whole bunch of folders which are in a certain directory, creating one zip file per folder. To do that, I use the following command: $ find -maxdepth 1 -mindepth 1 -type d | xargs -I@ ...
user avatar
  • 2,191
0 votes
1 answer
26 views

bashscript for quick change i3 mod key

i am trying to write a bash script to quick change the $mod key of i3 i moved the "set $mod Mod4" to the end of my conf #!/bin/bash $1=key $alt="alt" $win="win" sed '$d'...
user avatar
1 vote
1 answer
36 views

Is there any way to make autocompletion work for command option names in Bash?

I'm using Bash 4.4. [root@192 ~]# bash --version GNU bash, version 4.4.19(1)-release (x86_64-redhat-linux-gnu) Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or ...
user avatar
0 votes
0 answers
24 views

Scheduled cron job not running on MacOS [duplicate]

Here is my crontab. 3 13 * * 1-5 * * * * * /Users/smveerap/cron.sh >/tmp/cronStdout.log 2>/tmp/cronStderr.log 0 12 * * 1-5 * * * * * /opt/homebrew/bin/python3 ~/git/bashFiles/gitUpdate.py >/...
user avatar
0 votes
1 answer
30 views

How I get values from a JSON document in bash?

I want to write a script that finds my unused volumes in AWS. (the 'status' of used volumes is 'in-use'). When I use the aws ec2 describe-volumes --filters Name=status,Values=available I got the next ...
user avatar
-2 votes
2 answers
41 views

Why does echo in Bash modify the content of a independent variable?

I have the following code (minimal example). #!/bin/bash ...
user avatar
  • 192
0 votes
3 answers
35 views

If the value in the first column is the same, compare second column and if the second one is different save the value in the first column in txt file

I try to write script to get the the values from the first column, which are the same, but have a different value in the second column. Does someone know how to do it ? Example: I have this .txt file: ...
user avatar
0 votes
0 answers
60 views

How to use output from grep to rename the folder that contains the file that grep found the wtring in

I am working on a script that extracts log files from a SAN The storage array has multiple "nodes" in a cluster. The diagnostic logs pulled from the array are called an autosupport. The ...
user avatar
0 votes
1 answer
18 views

Installing node 14 on centos 7, how does it work?

The code for installing node 14 on centos7 is: RUN curl -sL https://rpm.nodesource.com/setup_14.x | bash - RUN yum -y install nodejs How does it work? The first command downloads the package. Where ...
user avatar
  • 101
1 vote
0 answers
13 views

Output capturing and make under Cygwin: "Unable to initialize device PRN" [closed]

A minimal example of the problem under Cygwin: A directory with a Makefile: all: @echo "foo" and a test.sh: #!/usr/bin/bash x=$(make) print $x Now bash test.sh gives: Unable to ...
user avatar
  • 151
0 votes
3 answers
57 views

Separate paragraphs using linux

I have a text file that contains connected paragraphs. I need to separate each paragraph with a blank line. Each paragraphs should begin with an >FP0 pattern, however because the paragraphs are ...
user avatar
  • 3
0 votes
2 answers
59 views

iconv cannot convert from ASCII.. why?

I have this file. If I open it in Total Commander with F3 and press S the proper content will be shown. I tried to do the same thing in bash with iconv: iconv -f ASCII -t UTF8 input.txt but I got this:...
user avatar
0 votes
6 answers
106 views

How to cut string on last underscore character?

I have list of files like below: [root@ods1 backup]# ls -l total 93892810 -rw-r----- 1 root root 651248 Feb 17 08:34 abc_def_g_17-02-2022.sql -rw------- 1 root root 665248 Mar 23 08:46 bbc_23-03-...
user avatar
1 vote
2 answers
43 views

How to execute a string of bash command with command substitution

Suppose I have a bash variable like this: tmp1='$(echo foo)' or tmp2='`echo foo`' How to achieve foo as result? I know that removing the command substitution from the string should work, but is ...
user avatar
0 votes
1 answer
29 views

How to store inner output of a nested bash command (within parenthesis) into one file and outer output into another file?

Here's my command: (time ( \ time sleep 1; \ time sleep 2 \ ) 2>&1 | tee inner.txt ) 2>&1 | tee outer.txt cat inner.txt shows: real 0m1.003s user 0m0.001s sys 0m0.002s real ...
user avatar
2 votes
1 answer
189 views

How to pass optional arguments to `time` command [duplicate]

man time shows it has some options, like this, to write just the time output to a file instead of to stderr: -o FILE, --output=FILE So, I try to use it $ time -o out.txt ls -o: command not found ...
user avatar
1 vote
1 answer
45 views

Is there a command to get the current memory address of the current shell script/command?

I wanted to do some protection against the memory dumping when users can recover my shell script's commands using the (delete) tag and then recover it from its memory address. So I thought it could ...
user avatar
  • 111
2 votes
0 answers
17 views

bash: debug (xtrace) target of redirections

Is there a way to show redirections with bash -x? $ bash -exc 'for word in foo bat baz; do echo $word >$word; done' + for word in foo bat baz + echo foo + for word in foo bat baz + echo bat + for ...
user avatar
  • 21
1 vote
1 answer
17 views

Pipefail prevents command substituation from evaluating pgrep?

My goal is to run a pgrep lftp -c command inside a shell script to check if lftp is already running. But the following script never goes beyond "test" output. Only if I remove the pipefail ...
user avatar
0 votes
2 answers
64 views

Understanding functions (Bash)

I see the below function used in a bash script: LOG_FILE="/root/collect.log";\ date_info() { local cmd; cmd=$(basename $0) echo "$(date --rfc-3339=seconds) $cmd.info: $*&...
user avatar
  • 1
0 votes
1 answer
16 views

using heredoc in case statement for remote ssh host

I have a list of ssh commands to run on remote server, so wrote this snippet. #!/usr/bin/env bash echo '' echo "WOULD YOU LIKE TO PERFORM FILES CLEANUP: " read choice case $choice in yes|...
user avatar
  • 1,631
4 votes
1 answer
115 views

Creating folders and subfolders coming from a text file

I have a scenario which will create a new directories coming from a text file. newDirectory.txt /test/test1 /test/test1/test2 I used this code but I tend to get double test1 subfolder while IFS="...
user avatar
  • 41
0 votes
3 answers
35 views

Adding matched string plus additional string after match in same line

I know the title sounds a little confusing, but hopefully my example will clarify my issue. So I have a file with a list of names (names.txt), for example: john david richard I'm trying to use a ...
user avatar
0 votes
3 answers
35 views

Splitting a file into separate files based on a keyword on a particular column of each header line

I would like to create separate files based on the first chromosome mentioned in the header line. There are 24 chromosomes mentioned in the header line and their sequences are mentioned in the next 2 ...
user avatar
0 votes
2 answers
43 views

sed and variables-substitutions on an custom script

well i ask here because i have around 12 hours trying with examples on internet for put a replace with sed on a custom script. In the file a had a lots of lines but i want to replace values after &...
user avatar
  • 29
0 votes
0 answers
41 views

script ping and traceroute

Creation of a script allowing to record the traces (log) of the ping and traceroute according to a list resulting from a flat file listing the various sites of Reunion and Mayotte. For the need, it is ...
user avatar
2 votes
1 answer
66 views

Wildcard expansion doesn't happen when Bash script invoked from cron under macOS

I have a Mac mini running macOS Monterey, and it has InfluxDB running in a Docker container. I'm trying to set up a nightly cronjob via a shell script I'm calling to back the data up, zip it, and only ...
user avatar
0 votes
1 answer
48 views

how to modify the color of fields of ls -la?

I recently found an example of colored output when using ls: AFAIK that is on MacOS with the BSD implementation of ls. I know how I can change the color of the filenames via LS_COLOR, but I would ...
user avatar
  • 1,066
0 votes
0 answers
19 views

String concatenation failing after personal access token [duplicate]

What specific syntax needs to be changed in the commands below in order for the end result of the commands to produce the expected value of https://ghp_fyrwTOKEN_REDACTEDgugg@github.com/...
user avatar
  • 5,084
0 votes
1 answer
50 views

bash script for batch trimming of pdf files

I have multiple pdf files in a directory. I want to leverage a pdf library that saves certain pages in a new file, probably a separate output folder. What's the best way to do it? This is the code ...
user avatar
1 vote
1 answer
34 views

How to pass date variable in SFTP data path?

I need to create a path with a variable value which contains yesterday date. I need to get files using SFTP. Here is my try. #/bin/bash TS=$(date -d '30 mins ago' +"%Y%m%d") sshpass -p '12#...
user avatar
  • 41
0 votes
1 answer
43 views

Why does $(RANDOM) work differently from $(ls -la)?

for command substitution in bash, we do this hello=$(ls -la) echo "$hello" but when i do the same for below command,it fails,it says RANDOM not found hell=$(RANDOM) echo "$hell"...
user avatar
0 votes
0 answers
34 views

Get a PulseAudio Sink Input based on application.process.binary

The command pactl list sink-inputs will print a list of all sink inputs, each one contains a series of properties and some will have the application executable under a property called application....
user avatar
  • 101
0 votes
1 answer
47 views

How to use if function in shell scripts?

I need to use if function to filter out required files only when using SFTP to copy files to my server from a remote server. Here is my try to get the all data inside /filesnew. #!/bin/bash files=`...
user avatar
  • 41
0 votes
1 answer
36 views

convert a uint8 array ( javascript new Uint8Array() ) to binary format (or binary mode ?) in shell / bash?

The question is about convert from new Uint8Array() generated from javascript into a normal file (file that can be used with other programs like ffmpeg) ** I don't know the right term to use if it's ...
user avatar
  • 115
0 votes
2 answers
88 views

How to quantify POSIX extended regex?

Password should start with a capital (uppercase) letter Password should contain a lower-case letter Password should contain a number Password length should be a minimum of 8 and less than 16 ...
user avatar
  • 125
-1 votes
2 answers
81 views

BASH script w/ functions won't run on startup

I have a BASH script that runs fine in terminal. But when I try to get it to run on startup, nothing happens. It seems related to the fact that the script uses functions. When I break the commands out ...
user avatar
  • 159
0 votes
1 answer
42 views

Is there a with context or function decorator in bash?

I use several small bash utility functions, which all start with "set -ux" and end with "set +xu". How can I avoid such repetition? In python, I'd use a function decorator or with-...
user avatar

1
3 4
5
6 7
482