Skip to main content

All Questions

Tagged with
1 vote
3 answers
84 views

Bash/macOS: Getting a variable by its name, inside of a function [duplicate]

In Bash for macOS, I need to be able to pass a string to a function and return the value of a variable named after that string, as well as the string itself. Here's what I have so far, which doesn't ...
seagull's user avatar
  • 111
-4 votes
1 answer
98 views

How to protect variable name inside shell arithmetic?

Variables can be protected with curly braces. Mynewvar=1 echo $Mynewvar 1 echo ${Mynewvar} 1 However I can no longer protect them when inside shell arithmetic. Mynewvar=1 echo $((Mynewvar+9)) 10 echo ...
jwav629's user avatar
1 vote
1 answer
75 views

Separate variable scope spawning commands under job control

Is is possible in bash - or other sh-derivative shell - to run in the foreground from command-line a list of commands that have their own variable scope (so any values assigned to variables in that ...
S P Arif Sahari Wibowo's user avatar
-1 votes
1 answer
177 views

shell endless loop for find command

I was working on a shell script where I came across this problem that I couldn't solve The following command is supposed to find all shell files in /. PATHS_SHELL=$(sudo find / -name '*.sh') ...
Kibnakamoto's user avatar
0 votes
1 answer
1k views

Variable expansion with sh -c executed over ssh

I'm trying to execute an command via sh -c over SSH in an LXC container. Since lxc-attach is involved I have to use sh -c like this: ssh <host> "lxc-attach -- sh -c \"<command>;&...
Harry's user avatar
  • 1
2 votes
1 answer
133 views

count variable not getting incremented

I have a scenario where I am running the following code: error_count=0 (cd tmp1 && terraform init -backend=false > /dev/null && terraform validate && echo "Terraform ...
Jenifer's user avatar
  • 85
0 votes
0 answers
155 views

Disable Bash completion for a single environmental variable

Suppose I have an environmental variable $SAVE_DIR=/etc/ used to return to a saved directory (here /etc/) from any Bash shell. Typing cd $SAV[Tab] expands to cd $SAVE_DIR which is quite convenient. ...
pip's user avatar
  • 121
-1 votes
1 answer
548 views

Define multiple variables inside while loop

I'm currently reading from a csv file and iterating through each line to define variables in some columns that I will use later. Say my csv file looks as follows: Column1,Column2,Column3,Column4,...
4rb3l's user avatar
  • 71
2 votes
0 answers
125 views

Why `declare -p VAR` returns "declare -- VAR" on an unset local variable but gives an error "bash: declare: A: not found" on an unset global variable?

I don't understand: $ declare -i VAR=0; \ > echo "$A"; \ > fun() { local -i VAR=1; echo {; echo "$VAR"; declare -p VAR; unset VAR; echo "$VAR"; declare -p VAR; echo ...
The Quark's user avatar
  • 270
1 vote
2 answers
222 views

Linux: parser variable from set command to bash file

I am trying pass a variable from the set command to a bash script. $ set BeginTime=2021-10-11 2:23:00 & ./getBeginTime.sh File getBeginTime.sh: local getBeginTime=$(set | grep BeginTime) echo &...
Long Tran's user avatar
4 votes
1 answer
1k views

What exactly happens when I type " unset * " in prompt?

Say I connected to a Linux system as root. What exactly happens when I type unset *?
Lunartist's user avatar
  • 405
1 vote
1 answer
753 views

How to do output of both variable and it's value to a file

I'm struggling a bit with this task, for example I can do a simple loop to send variables values into a file with for loop. But how to get something before output of the variable value? I did ...
Dawid's user avatar
  • 13
1 vote
1 answer
104 views

My multiple variables in a function do not get expressed as aliases. I think my syntax is faulty

In bashrc, I have this alarm function which can take 3 variables: a () { local $1="${1:-3600}" local $2="${2:-paa}" local $3="${3:-alarm}" sleep "$1" && $2 && $3 } alias ...
MarkB's user avatar
  • 35
5 votes
1 answer
22k views

conditional binary operator expected

var="$(command1 -l '$var2' -c 'command2|grep -c "search"')" if [[ var !=0 ]]; then fi Why am I getting "conditional binary operator expected". I searched already and. I. see that [[]] is a test ...
iControlEIP's user avatar
3 votes
3 answers
4k views

Multiple commands and subshell execution after pipeline

Ok, I know that in Bash (by default, without 'lastpipe' bash option enabled) every variable assigned after a pipeline is, indeed, executed in a subshell and the variable itself dies after subshell ...
JohnC's user avatar
  • 41

15 30 50 per page
1
2 3 4 5
7