Skip to main content

Questions tagged [variable]

A variable is a name, if correctly chosen with a symbolic meaning, that holds a value or values. Use this tag if your question is specific on the use of variables on shell scripting (if you want to ask about variables in programming languages you should probably ask on StackOverflow)

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

What do I want : On the file manager lf, we can bind some keyboard shortcuts to do either a lf command with :, or a shell command with $, !, or other symbols. According to the documentation, there is ...
ewen-goisot's user avatar
0 votes
1 answer
63 views

Can anyone explain what's going on with DR here? user@host:~# DRYRUN=true user@host:~# echo "$DRYRUN" true user@host:~# $DRYRUN && export DR="-n" user@host:~# echo $DR user@...
Hugh's user avatar
  • 19
0 votes
0 answers
38 views

I have a script which is supposed to fetch 2 URLs sequentially: #!/bin/bash wget_command='wget --restrict-file-names=unix https://www.example.com/{path1,path2}/' $($wget_command) echo $wget_command ...
MonkeyZeus's user avatar
0 votes
2 answers
189 views

This code my_file="/tmp/file_without_spaces" if [ -f "${my_file}" ]; then my_ls_aaaammgg_hhss="$(ls ${my_file} -l --time-style='+%Y%m%d_%H%M%S' | cut -d' ' -f6)" mv &...
CarLaTeX's user avatar
  • 331
-1 votes
2 answers
106 views

whats wrong with this bash script: acme2=$(dig txt @$1 _acme-challenge.$1.de) acme3=$(echo $acme2 | grep "^_acme") ...
dg1kpc's user avatar
  • 1
-3 votes
1 answer
88 views

In the Bash manual, it is written about the tilde expansion: Each variable assignment is checked for unquoted tilde-prefixes immediately following a ‘:’ or the first ‘=’. Read the Bash manual about ...
Kiki Miki's user avatar
1 vote
3 answers
146 views

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
1 vote
1 answer
90 views

General overview I have to set a values auto-completion in zsh for a command (in the following minimal example, I will show it with testcmd). So my current code work quiet well with hardcoded values: ...
fauve's user avatar
  • 1,529
1 vote
1 answer
60 views

I need to assign a command to a variable and execute it with variable in linux bash. The command executes fine from command line but not from the variable because of multiple quotes. I hope backslash ...
Kishan's user avatar
  • 113
5 votes
4 answers
623 views

I would like to execute a script on a host machine (script_on_host.sh), which then reaches inside a docker container in order to grab some data using a second script (script_in_container.sh). The data ...
teeeeee's user avatar
  • 305
3 votes
1 answer
210 views

I am configuring my hyprland.conf file and I am attempting to do it in a clean and modular fashion. I am trying for a modular fashion so that I can share my dotfiles and someone else can change which ...
PrismaPixel Studios's user avatar
-1 votes
1 answer
159 views

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
  • 470
1 vote
1 answer
93 views

In this test I'm expecting it to print "var1 is 999". user@penguin:~$ for num in {1..3}; do export var$num=9999 ; echo var$num is $var$num ; done var1 is 1 var2 is 2 var3 is 3 user@penguin:~...
Dan Larrabee's user avatar
2 votes
2 answers
523 views

I looked through some of the posted threads and none of them cover my query. I have a simple line of code below which prints all the ASCII characters: echo {' '..'~'} I want to be able to use a ...
James Bond's user avatar
0 votes
3 answers
413 views

I have a json object that has an unknown number of variables, like this: { "var1": 123, "var2": 456, "var3": 789 } How can I automatically convert it to form ...
teeeeee's user avatar
  • 305
5 votes
1 answer
366 views

Yes I read Communicating Options to a Sub-'make' but I want to set an option for this make, not a sub-make, and set it within the Makefile, not via the command line. $ cat Makefile MAKEFLAGS = --warn-...
Dan Jacobson's user avatar
0 votes
1 answer
57 views

Does Bash have an option to diagnose (and optionally abort execution) "expanded to empty value" variables? Example (hypothetical): $ bash -c 'echo $x' --xxx bash: line 1: variable 'x' ...
pmor's user avatar
  • 757
2 votes
1 answer
482 views

Bash accepts both these syntax: FOO=$(($BAR + 42)) and FOO=$((BAR + 42)) Which one is correct / most portable / less prone to errors? Or are both equally valid?
dr_'s user avatar
  • 32.4k
7 votes
1 answer
282 views

$ perl -wle 'my @388=0..2;' Can't use global @388 in "my" at -e line 1, near "my @388" Execution of -e aborted due to compilation errors. $ perl -wle '@388=0..2;' $ Where can I ...
Dan Jacobson's user avatar
0 votes
1 answer
217 views

I want to extend question How to store standard error in a variable and get general solution (bash function or functions) to extract from the called function/command together with standard error also ...
Anton Samokat's user avatar
-1 votes
1 answer
56 views

I would like to know why the following shows an empty dialog box: testvar="hello" & zenity --info --text "${testvar}" While this works: testvar="hello"; zenity --...
robertspierre's user avatar
0 votes
2 answers
110 views

basic, innocent question: In bash scripting, why ever using a function, if one can set a variable containing command substitution with the essence of the function - a certain command or set of ...
futurewave's user avatar
7 votes
3 answers
1k views

I'd like to prepare a test for a REST petstore server by the mean of curl. To test its add new pet api, I prepare a json string that holds the Pet to insert in a bash function that executes the curl: #...
Marc Le Bihan's user avatar
0 votes
0 answers
256 views

I was writing a shell script for inserting a string value through a Microsoft sqlcmd variable into a Microsoft SQL server database table and noticed some unexpected behavior. It appeared the trailing ...
Mark's user avatar
  • 101
7 votes
1 answer
2k views

Instead of the following printf '%s\t%s\t%s\t%s\n' 'index' 'podcast' 'website' 'YouTube' I want to store the printf output in a Results variable, how can I do this?
Porcupine's user avatar
  • 2,176
0 votes
2 answers
221 views

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
526 views

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
0 votes
1 answer
87 views

I'm compiling Nginx from source on Debian 12 in Bash. I'd like to select the TLS vendor (e.g. LibreSSL, OpenSSL) via a preflight variable ($nginx_tls_vendor). An example configure command without the ...
Pete Cooper's user avatar
0 votes
1 answer
82 views

$ bash --version GNU bash, versione 5.2.26(1)-release (x86_64-pc-linux-gnu) I don't know how to deal with $VAR when its value inside contains single quote (') and/or backtick (`). I'm in the need of ...
dAllARA's user avatar
  • 33
5 votes
1 answer
331 views

Assuming I have a variable v="c d e f g" and a file with the content: line1 $v line3 How can I make a bash script print this file with the content of the variable in line 2 as if I was ...
nath's user avatar
  • 6,104
0 votes
1 answer
134 views

Consider the following example: $ echo file_{a,b,c} file_a file_b file_c # brace expansion worked :) $ export VARIABLE=file_{a,b,c} $ echo $VARIABLE file_c # brace ...
Thomas Fritz's user avatar
1 vote
1 answer
153 views

From man bash: -n string True if the length of string is non‐zero. Examples: # expected $ var=""; [ -n "$var" ]; echo $? 1 # unexpected? $ var=""; [ -n $var ]; echo ...
pmor's user avatar
  • 757
5 votes
2 answers
1k views

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
0 answers
46 views

In Ubuntu 18.04 and 22.04 (WSL), I've noticed that $PS1 contains a "bell" character, \a: $ echo $PS1 \[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\...
AJM's user avatar
  • 295
-1 votes
1 answer
281 views

I defined the following as read-only: readonly root_command='sudo -s' later used in my script as in: exec $root_command My question is, maybe I am slow or something, but I do not fully understand ...
Vlastimil Burián's user avatar
0 votes
1 answer
481 views

Variable USE_TLS is to be unset, null, or empty when TLS is not to be used, but set to 1 when TLS must be enforced. I require it to be enforced by default (i.e., set), but not if I specify another ...
Code Maverick's user avatar
1 vote
0 answers
180 views

I've created a bash script that Lists the document IDs I've put in an Elastic index, in $liste_ids_lines: a004-événements-examen_individus_localisés_ou_non a020-les_points-leurs_indicateurs-...
Marc Le Bihan's user avatar
1 vote
2 answers
251 views

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
1 vote
1 answer
363 views

I am trying to change the "hostname --transient" to some computers with a for loop using a variable. I want it to collect the "hostname -f" from the server itself and, using the ...
henrolos's user avatar
0 votes
1 answer
186 views

I am reading a file with a matching pattern then getting the first five lines after the matching pattern. The patterns are not in proper numeric order, so I am using a numeric variable in the pattern ...
Joey Simon's user avatar
1 vote
1 answer
221 views

Why is it that zsh seems to understand what to do with some_variable=1 command, but not some-variable=1 command? E.g.: $ fs_screen=1 mpv --fs-screen=${fs_screen} someFile.mp4 works fine but $ fs-...
Harv's user avatar
  • 2,612
0 votes
1 answer
668 views

Have a nice day I have got text file (zz.txt): Chemical name 3-Aminopropane-1-sulphonic acid Synonym(s) -- Homotaurine * Tramiprosate -- Chemical name Common name and synonyms ... I have variable s=&...
Alex Den's user avatar
0 votes
1 answer
76 views

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
  • 663
1 vote
3 answers
97 views

I have 2 variables in a file like below that I need to assign a new value inserted by one user input: read -p "Enter CName Name : " CName sid=C02SBX SID=C02SBX When I run the following ...
Ali's user avatar
  • 123
0 votes
2 answers
610 views

I'm trying to replace only part of the existing variable with a new user input variable as below: #Current Variable: gdbName=Test.MY.DOMAIN.COM <--I need to replace the "Test" (This can ...
Ali's user avatar
  • 123
1 vote
0 answers
419 views

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
4 votes
2 answers
2k views

The following script, play_movie.sh is meant to automatically select a movie if there is only one in the current directory and play it with ffplay. Otherwise it is meant to display a selection of ...
John Smith's user avatar
0 votes
2 answers
441 views

I have 2 files: a file full of values I want to look for my source text file I wrote a short shell command to loop thru my list of values and grep against my source file. If it doesn't find the ...
Classified's user avatar
0 votes
3 answers
179 views

I have 2 systems and they have the same directory strcuture. I want to execute a couple of commands on local system and the same on remote system. I use the wildcards so when I have a new version of ...
DEKKER's user avatar
  • 998
0 votes
1 answer
325 views

I'm trying to learn bash scripting using freeCodeCamp tutorial for beginners on YouTube. I'm stuck at the point where he shows how to create a function. He saved on a variable a command with an option ...
Paul Marcelin Bejan's user avatar

1
2 3 4 5
25