Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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)

0
votes
3answers
64 views

Printing a Variable Which Contains $ Sign

I have a bash script which contains awscli as well. I am trying to print a variable which is created in a for loop. The variable that I am trying to print contains $ sign because of for loop. I couldn'...
0
votes
3answers
759 views

create variables from CSV with varying number of fields

Looking for some help turning a CSV into variables. I tried using IFS, but seems you need to define the number of fields. I need something that can handle varying number of fields. *I am modifying my ...
0
votes
3answers
73 views

How to create a script or a command line that increment the variable part of the name of my files but some of them?

I have several files whose names aren't correct: $ ls devoirNote1_1_2.R devoirNote1_1_5.R devoirNote1_4_1.R devoirNote1_1_3.R devoirNote1_1.R devoirNote1.R devoirNote1_1_4.R devoirNote1_2_1.R ...
2
votes
2answers
1k views

Using a Counter Loop for Environment Variable

I'm trying to write a code that moves files to a .junk directory using the built-in environment variables. My goal is that all a user would have to do is type sh junk filename1 filename2 filename3... ...
1
vote
2answers
157 views

MQTT as a variable on Bash?

Hi I want to try and convert a message receieved from MQTT into a variable so I can do an "IF script" using messages sent from a certain topic on mqtt. I tried this at top of script but didn't work: ...
1
vote
2answers
31 views

Linux Shell - Certain Variables and Methods NOT appending to text file

I'm having an issue getting the variables $myname, $filename, and a method that counts all the records in another file, wc -l < hs_alt_HuRef_chr10.fa >> "$CuestaP.txt, to append to the text ...
1
vote
2answers
566 views

how to assign log as a variable in bash

I want to assign log output to "line", I tried the following line=tail -1000 /var/log/syslog but it doesn't work. myscript is like below #!/bin/bash line=`tail -1000 /var/log/syslog` d1=$(date --...
0
votes
2answers
223 views

Finding the Percentage from a grep variable

I want to display the calculation of the CPU load in percentage. num2=$(uptime | grep "average:" | tr -d " " | cut -d ':' -f 5 | cut -d ',' -f 2) percent=$((num2(*100))) echo 'CPU percentage' $...
0
votes
2answers
249 views

How to add ip as a variable to pxe cfg file

I am installing my linux OS using PXE and I want to automate my process using variables or files. I need to know how can I import the ip address from another file and add it as a parameter to pxe ...
0
votes
2answers
114 views

Pass month name dynamically in AWK (GNU) with control statement

Hi I'm trying out below command to match month and day (of 6 days ago, which is Jun 29) to search a directory using AWK, but the result is always '0' instead it is supposed to be around 1800. ls -ltr ...
0
votes
2answers
1k views

Choose random string from a few and set it as a variable?

I have a few strings, and I want to set a variable to one of them, randomly. Say the strings are test001, test002, test003 and test004. If I set it like normal I'd obviously do it like this: test=...
-2
votes
2answers
536 views

shell shell scripting with oracle

I am trying to substitute a unix variable to a select statement, but I am getting the below error. What did I do wrong? sqlplus "/ as sysdba" << EOF spool /home/oracle/l.log archive log list; ...
2
votes
1answer
712 views

Where are Kernel global variables stored?

I am currently writing a Linux kernel module. I am aware that in case of userspace programs, uninitialized global variables (exported to other modules using EXPORT_SYMBOL) are stored in BSS segment ...
1
vote
1answer
56 views

Declaring a variable that does not have input

I would like to be able to retrieve input from my shell history in order to set variables inside my script. I would then like to use these variables in an if loop, but I am unable to get the variable ...
1
vote
1answer
153 views

pass the value of variable from a script to another script from another server

I have a script that will ssh to another server. Script A will get the value of $variableA, then will ssh to another server to execute a script B which will need the value of $variableA. I tried ...
1
vote
1answer
328 views

Make all variables readonly and local by default in bash

When building bash scripts, I use a lot of readonly, local, and even readonly local when making variables. That can rapidly fill your script and makes the code less readable (and repetitive). Is there ...
1
vote
1answer
590 views

call a shell script by using a variable

I have a shell script, that will internally call a variable (that stores a executable shell script) Shell script starts var=$(awk -F'|' '{print $2}' $TEMPFILE) The value in the variable is . /lapp2/...
1
vote
1answer
115 views

Ansible variables scope clash

I've got an ansible setup that looks like this inventories/ sandbox1 group_vars/ all sandbox1 pb/ pb1/ run_pb1.yml I've got roles and other stuff too, but I think ...
1
vote
1answer
61 views

Is there a way to localize variables to the current function in `mksh` but not to others?

Is there a way for $val to be set in a () but not be seen by b ()? set -u -e -o pipefail a () { local +x val="myval" echo "in a: VAL= $val" b } b () { echo "in b: VAL= $val" } a Produces: ...
1
vote
1answer
813 views

Shell script to backup VMware VM's, exporting each VM to a list then asking user intput

What I'm Trying To Accomplish: Get list of Virtual Machines ".vmx" file and place in variables Give the user and choice of which VM to backup Use "ovftool" to produce an export of the chosen VM to a ...
0
votes
1answer
32 views

Output of piped command to variable not working

When I try the following there is no problem: $ date '+%y%m' | sed 's/.\(.*\)/\1/' 906 But When I try to store it in a variable it seems nothing is stored: $ dd=`date '+%y%m' | sed 's/.\(.*\)/\1/'` ...
0
votes
1answer
31 views

Variable within path to file in bash script

I've got a file, that contains about 20k strings. Each string in that file should be an argument for a command within bash script. At first my script generates a file with this strings. find /home/...
0
votes
1answer
23 views

add a line to file that contains quotes and variable using bash

I want to add this line to /etc/grub.d/00_header set superusers="ubuntu" where ubuntu is the result of $USER. I've tried this: sudo bash -c 'echo "set superusers='"${USER}"'" >> /etc/grub.d/...
0
votes
1answer
22 views

Manually enter password into expect and use as variable while scrip is running

I have an expect script that uses interact every time a password is needed. The program that expect is automating asks for the password multiple times. Is there a way to only have to type the ...
0
votes
1answer
245 views

Can lftp get take in a variable name?

I want to have a script that uses lftp to download a zip file with a variable name. Currently I have the following: open server user user pass set ssl:verify-certificate no ls -ltA1 | grep .zip$ | ...
0
votes
1answer
39 views

How make each script run to expect different inner variable value?

Looking for advice. Writing a simple bash script. It will check percentage of income files in folder every 30 min. So we know expected total number of files and till what time they all should be in ...
0
votes
1answer
81 views

Variable Crossover in multiple bash scripts?

I have two bash scripts running simultaneously, which are identical apart from two things. Apart from a few other setup pieces they run the following entry: ssh ${target_server} "bash -s" < ${...
0
votes
1answer
106 views

Issues with storing an echo of a date conversion into a string variable inunix

Apologies but this question comes from a question previously raised: How can I convert a local date-time into UTC date-time? Toby has been absolutely great helping me with some conversion string-->BST ...
-1
votes
1answer
52 views

for loop # usage

I am trying to understand how this piece of code works: for b in `git branch -r`; do git branch --track ${b##upstream/} $b; done In particular, the part where it does ${b##upstream/} I know it ...
2
votes
0answers
509 views

Running R script and global variable overriding with <<- from cron

I have a R script that works just fine when I run it from RStudio. However, once I schedule it through cron under user RStudio only with home directory (/home/rstudio), it halts at the very step I ...
2
votes
0answers
568 views

Evaluate variables' value in Kickstart file

I am trying to make a Kickstart install of a CentOS 7 VM interactive, by asking for user input in the %pre-install script, as described here. So far I've managed to get user-entered values and store ...
1
vote
0answers
19 views

How to clear DISPLAY variable in GNU screen

Basically, i need to unset DISPLAY variable in screen if I run multiple commands like: screen -dmS name bash -c 'kodi; unset DISPLAY; emulationstation' I'm writing a little something that will ...
1
vote
0answers
131 views

Bash variable value partially substituted in Curl input

Below is my shell script in which I'm trying to use the value of a variable as input to curl. However, the script is giving an error and when trying to debug the script, I can see that the value of ...
1
vote
0answers
170 views

Jenkins deploy doesn't pass variable to java

Problem that I ran into is that when we deploy our Java application via Jenkins hostname variable is not passed to it. Inside the script somewhere we define HOSTNAME=$(hostname -f) variable, which we ...
1
vote
0answers
96 views

How do you pass variables to jsc/javascript?

I have a few javascript things that I am running from the Terminal by passing them to jsc, with <<<. (javascript is an alias to /System/Library/Frameworks/JavaScriptCore.framework/Versions/...
1
vote
0answers
52 views

Moving to FHS 3: How to overwrite GNU Autotools directory variables?

In GNU Autotools, the directory variables $sharedstatedir and $localstatedir expand to $(prefix)/com and $(prefix)/var respectively. However the com and var directories don't exist anymore in FHS 3, ...
1
vote
0answers
805 views

passing variable through cat EOF command with for loop

How do I get the script run with the sbatch command to run with the 23 individual run_prep_chem_$dd.sh (i.e. run_prep_chem_08.sh...run_prep_chem_30.sh)? I am thinking since its in this for loop that ...
0
votes
0answers
46 views

Strange counting problem of variable in bash script

I have the following bash script which works fine until I get to number 9 (/dev/sdj) where it does not produce the expected output. hdd1="$(sudo fdisk -l | grep "Disk /dev/sd" | awk '{print$2}' | sed ...
0
votes
0answers
25 views

change global environment variable for all processes

I have two programs (lets say terminal A and terminal B) which both use a global environment variable to see if the other one changed something. I added UPDATED=0 to the /etc/environment file. Now ...
0
votes
0answers
36 views

Complex nested for loop in directory

I have two sets of files in two separate directories organized as such: #first directory /direc1/files file0.num1.tar.gz file0.num2.tar.gz file0.num3.tar.gz file0.num4.tar.gz . . . ...
0
votes
0answers
29 views

shell - mysqldump works with echo but not directly

Im preparing a shell script which will take mysql table dump with where clause. Im passing table name and where condition from a parameter. Backup command: mysqldump -u root-p'pass' db ...
0
votes
0answers
49 views

Variable assignment exit status

Normally, if has an exit status not zero, execution will continue: false echo 'this will show' If you use set -e, the shell immediately shall exit: set -e false echo 'this will not show' I am ...
0
votes
0answers
47 views

Add command output as variable; cross-platform syntax

1. Summary I don't find, how I can use command output as variable, use cross-platform syntax. 2. Example For example, I want get URL of my remote git repository: SashaChernykh@DESKTOP-EEOT0TN /...
0
votes
0answers
112 views

What mail variable is needed to make sure I receive a copy as well when emailing an alias

The alias includes a list of addresses and includes mine as well what mail variable do I need to make sure I still receive a copy of the message as well?
-1
votes
0answers
25 views

using case statement to read from a variable/file while creating a MENU

read -p 'enter your choice [ 1-5 ]' choice case $choice in 1)abcrequest 2)defresponse 3)afgRequestReply 4)FSfReply 5)ghjrequest I want the case ...