Skip to main content

All Questions

-1 votes
1 answer
78 views

Bash local nameref declaration does not work

I am trying to set a local variable in a function with nameref. The script code is the following: #!/usr/bin/bash msg=hello myparam='' superfunc () { productfile=$1 local -n refmyparam=$2 } ...
trikelef's user avatar
  • 460
0 votes
2 answers
172 views

how to replace a string with a variable?

I am trying to write a script containing a loop that enters a series of directories containing the same file, to replace a text string in a file with a variable that matches the directory's name. The ...
Ella Brudner's user avatar
5 votes
2 answers
478 views

Issue expanding variable with multiple wildcards in bash shell script with mv / rename

I wrote a bash shell script for Linux to move files in a static folder according to parameters specified in a data file. I've reduced that script to a minimal reproducible example to demonstrate an ...
Amazon Dies In Darkness's user avatar
5 votes
2 answers
938 views

Is it while loop or the pipe causing global variable behaving unexpectedly

Could please someone explain the (from my POV) strange behavior of the COUNTER variable in the following code? #!/bin/bash COUNTER=0 function increment { ((COUNTER++)) } function report { ...
Jozef Chocholacek's user avatar
1 vote
2 answers
212 views

Redirect to a filename that will be a variable and contain a command substitution

I'm using nmap to scan a network and then create an XML file that contains the scanned information. I want that XML file to contain the date of the scan so that each file is unique and I can see the ...
johnmacward's user avatar
0 votes
1 answer
55 views

Bash script variable syntax: with some commands it works, with others it does not [duplicate]

I do not understand the behaviour of this variable: SSH_CONFIG_FILE="~/.ssh/config" echo $SSH_CONFIG_FILE ls -l $SSH_CONFIG_FILE ls -l ~/.ssh/config This is the output: ~/.ssh/config ls: ...
Pietro's user avatar
  • 653
1 vote
0 answers
360 views

Extract from a curl its dire failure message (if case of return code != 0), status code, output, and error message into four different variables

I need to extract from a curl emitted: the bash error message coming with a non-zero ?$ return code, in case my command would direly fail the http status code returned by the server contacted the ...
Marc Le Bihan's user avatar
1 vote
0 answers
139 views

Can you assign a default array to a variable by specifying its values explicitly?

I know that I can use an existing array as the default value for a variable that is potentially uninitialized via default_values=(1 2 'value is a string') array=("${array[@]-${default_values[@]}}&...
da22e's user avatar
  • 11
1 vote
1 answer
288 views

Script to select a PulseAudio sink from an ordered list and use its name as command input

I wish to write a bash script that will create a PulseAudio loopback device between an audio source and a bluetooth device. (Context - skippable) So far I have (the relevant part of) my script as: ...
Marc.2377's user avatar
  • 1,132
0 votes
2 answers
247 views

How to get the Path difference and store it in a variable

Suppose I have two paths. Path1 which is static and path2 which is dynamic. Example: Path1= /tmp/folder/ Path2= /tmp/folder/dir1/dir1_2 Result: Diff= /dir/dir1_2 I want to achieve as above example....
Asif Ahmed's user avatar
0 votes
2 answers
52 views

How to pass commands around?

I have this simple script, which does nothing more than: check if an email matches a specific pattern in that case, add a tag to a taglist before quitting, print that taglist set -e lista_tag=() ...
gobbolo22's user avatar
0 votes
2 answers
176 views

Use a variable value only for x times

I am making a bash script where I need to run a command using a specific ID. But a single ID can be used only 10 times. After that the ID should change For Example I have three IDs ID=(abcd1 abcd2 ...
ph3ro's user avatar
  • 378
0 votes
1 answer
48 views

How to use the full variable value by mentioning some part of it in command line

I want to create a script where I can just use a variable by mentioning some part of its string in arguments for example : #!/bin/bash ipv4_5784_4679=1.1.1.1 ipv4_7838_7782_8987=2.2.2.2 echo "...
ph3ro's user avatar
  • 378
0 votes
1 answer
294 views

Can't access variable outside the function even it isn't local

I have simple bash script. My bash version is GNU bash, version 4.4.20(1)-release (x86_64-redhat-linux-gnu) #!/bin/bash func() { nlvar="i'm not local variable" local lvar="i'...
kobayashi's user avatar
2 votes
1 answer
210 views

Setting the value of variable1 according to value of variable2

I have a bash script which is executed as below ./myscript.sh --tourney --port 22456 --matchid 5 I have a variable named matchteams. Now there are list of match teams which are according to the id. ...
ph3ro's user avatar
  • 378

15 30 50 per page
1
2 3 4 5
12