Skip to main content

Questions tagged [eval]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
0 answers
18 views

While Loop Exits After Calling Function [duplicate]

I'm trying to do a db backup script using Bash. When adding a "Resume" feature to the script, I do the following loop calling defined functions to do step by step (depending on the .lock ...
James's user avatar
  • 111
0 votes
2 answers
94 views

Confusing results of eval + sed combination [closed]

I run a game from steam which starts with the game companies launcher app where I have to click another button to start the actual game. The game launcher is very slow, contains needless advertising, ...
nobody special's user avatar
0 votes
2 answers
307 views

eval: $? vs ${PIPESTATUS[@]} (bash)

In bash 5.0, I wish to capture the ${PIPESTATUS[@]} of a piped command that is executed via eval. However, eval appears to mask ${PIPESTATUS[@]}, but doesn't mask $? which is the equivalent to ${...
jitter's user avatar
  • 5
0 votes
1 answer
650 views

Sanitize input that is used to update script

Looking at a bash-script that takes input from Git commit comment to update itself. Simplified: script: #!/bin/bash comment='' printf '%s\n' "$comment" upgrade_script() { # ...
Err488's user avatar
  • 25
0 votes
1 answer
59 views

Shell script: Using variables makes command fails ( substituting values of variables manually ; command works fine )

In a bash script: jenkins_folder=`cut -d "|" -f1 -s input.csv` jenkins_url='https://url.com:8181/jenkins/view/' echo "jenkins_folder : ${jenkins_folder}" for job in ...
Deepak Singhal's user avatar
3 votes
4 answers
609 views

awk or perl to eval mathematical expressions in each line

I want a script to make awk to become an interactive mathematical calculator, to eval mathematical expressions given in each line. I.e., instead of constructing awk commands to calculate expressions ...
xpt's user avatar
  • 1,682
1 vote
1 answer
840 views

Command output evaluation not working in Bash script [duplicate]

I am trying to automate adding Homebrew to my path in a shell script, but these two lines do not evaluate inside my shell script: #!/bin/sh eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)&...
unrealapex's user avatar
-1 votes
1 answer
95 views

use a variable as a variable

I'd like to use a variable variablenaam for using in a loop. I tried for hours but can't make it work. My experiment in bash on a RPi 4 with the latest Raspbian. I like to make the use of xstack1 and ...
pvk's user avatar
  • 5
0 votes
1 answer
349 views

Declare variable in eval Bash

There is a way to declare variable in eval ? For example function test { eval $1 } test " value="foo" echo "$value" " But it display nothing. ...
RevOneX9's user avatar
0 votes
0 answers
282 views

How does one store the evaluation of a big string with multiple env variables $VAR into another env variable?

Becuase I need to make sure I run authentication for my nohup commands I need the real command I want to run to be in a string in here: nohup sh -c 'echo $SU_PASSWORD | /afs/cs/software/bin/reauth; ...
Charlie Parker's user avatar
0 votes
2 answers
341 views

Bash: how to wrap a command to measure its elapsed time?

How to wrap a command to measure its elapsed time? Currently I do it using eval: do_cmd_named() { local name=$1 local cmd=$2 echo "$name" local start_time=$(date +%s) eval "$...
pmor's user avatar
  • 629
1 vote
1 answer
90 views

Bash - How to make dynamic menu selection without eval

I'm making a script for Docker environments, and I'm a bit stuck with a pigeonhole I've gotten myself into. #!/bin/bash set -euo pipefail # Variables gituser="modem7" gitrepo="docker-...
Modem7's user avatar
  • 11
0 votes
1 answer
902 views

Using `env` command with `eval`

Suppose I have this in script.sh: env -i SOMEVAR=SOMEVALUE eval -- "$@" I run it with: ./script.sh echo "\$SOMEVAR" Now it shows: env: ‘eval’: No such file or directory I ...
sudoer's user avatar
  • 55
0 votes
2 answers
69 views

get value of variable which is prefixed by another variable in bash

I'm running offlineimap on a bunch of accounts and want to check the exit code of each run and perform some actions accordingly. I have 6 separate email accounts that I run against with a lot of code ...
Tony Barganski's user avatar
0 votes
1 answer
215 views

Iterating through a command list using heredoc

This works fine: $ eval 'echo "1" > ~/Desktop/in/foo' But not this: $ while IFS= read _cmd; do eval "$_cmd"; done < <(cat << EOF 'echo "1" > ~/Desktop/...
Erwann's user avatar
  • 677
0 votes
1 answer
72 views

Difference between eval execution of a command and assigning the result of the command execution to a variable

In the following script #!/bin/sh CMD="ls -al" Z=`$CMD` echo $Z echo "-----" eval $CMD what is the practical difference of the invocation of ls -al via $CMD and eval and why ...
pkaramol's user avatar
  • 2,939
2 votes
2 answers
14k views

Handling long-options with getopts

I am parsing options with getopts but would like to handle long-options as well. print-args () { title="$1" ; shift printf "\n%s\n" "${title}: \$@:" for arg in "$@...
Vera's user avatar
  • 1
0 votes
1 answer
92 views

Why doesn't `eval` work in this code?

I wrote the following code which is meant to create a file with a list of low-resolution media files: #!/usr/bin/bash find "$PWD" -type f -iname "*.avi" -execdir ~/CS/...
John Smith's user avatar
0 votes
2 answers
129 views

How to run eval with lockf command?

I have a command which I run via eval as shown below. #! /bin/sh readonly scr="MYENV=1 sh /tmp/scr.sh" eval ${scr} -a 1 -b 2 Now I want to run the scr script with lockf utility, so I made ...
Rahul Bharadwaj's user avatar
2 votes
1 answer
1k views

Evaluate multi-line output (with comments) of another command. (pip-completion)

In trying to make my .zshrc neater, I stumbled over the following problem/question: "How can I run the output of another command?". While I'm sure this is a simple problem, I just don't ...
Alexandru Cristiean's user avatar
1 vote
1 answer
302 views

Security implications of executing strings using eval in bash

Consider the following: $ a='friend' $ b='printf "%s\n" "$a"' $ eval "$b" friend This should be completely safe. Let's however say that $b is the same but $a is unknown. ...
fuumind's user avatar
  • 449
16 votes
10 answers
5k views

What are some useful use-cases for eval in Shell?

You hear it a lot eval is evil, whether it's in Shell/POSIX world, or in other langs like python etc... But I'm wondering, is it actually useless? or is it there some arcane, non-documented, ...
Nordine Lotfi's user avatar
3 votes
1 answer
353 views

Why does substituting eval with declare (for creating dynamic variables) result in an empty variable?

With bash >5, I'm trying to assign a different value to variables depending on the architecture specified in a variable. I use a function to do so. This works perfectly: # arguments: variable ...
DeadBranch's user avatar
0 votes
1 answer
236 views

Script using data/input which contains variable names [duplicate]

So I have a file "Directories.dat" that contains a list of directories for a script to read that runs on multiple machines. Due to this, the list of directories in the file is often defined ...
link's user avatar
  • 1
0 votes
2 answers
1k views

eval variable=command in the background

I have the following code for name in a b c d; do for i in {01..12}; do eval test_${name}_{i}=`some command` done done I am trying to do the assignments in the background but it doesn'...
ammar's user avatar
  • 87
4 votes
1 answer
3k views

How to conditionally redirect the output to files based on variable in bash

I'm trying to use eval command to eval a comment -- I'm not sure if this is the right way to do it. Example: i=?? (What I want here is either a #, to comment what's after, or blank) somecommand arg1 ...
Raywando's user avatar
  • 497
0 votes
1 answer
832 views

How to export lines from other file into current shell

I have this content in a file called foo.env: foo=bar and then I want to read that file and export the lines to the shell: for line in $(cat ./foo.env); do eval export $line done but when I run ...
user avatar
3 votes
2 answers
4k views

How can I write an `eval` command containing a new line into one line?

Since I need to set and use alias in the same line in bash, I would like to use Hauke Laging's workaround: eval 'alias df5=df df5 -h' (I took df and df5 for the sake of the example. I am aware that ...
Franck Dernoncourt's user avatar
0 votes
0 answers
18 views

Why running eval from cli works, but running script with eval inside it, it doesn't? [duplicate]

Why when I run eval $(keychain --quiet ~/.ssh/id_rsa) from cli it works, but if I try to do same from the script it doesn't work and $SSH_AUTH variables are not present?
Andrius Solopovas's user avatar
-1 votes
1 answer
799 views

Generating content stored under a dynamic variable in Shell Script

I am stuck with the below code and any help would be greatly appreciated: I am trying to assign contents inside a dynamically generated variable to another variable. But instead of the value of the ...
Mohammed Haleem S's user avatar
0 votes
0 answers
70 views

Can I avoid using eval in alias re-definition?

My system: Linux Mint 19.3. My default shell: Bash. Problem: I do not like using eval (man page) if unnecessary. Question: Is there another way of redefining stored alias, which I currently do as ...
Vlastimil Burián's user avatar
2 votes
2 answers
210 views

building an alias from a function

I need a lot of different aliases to create ssh tunnels to different servers. To give you a few of them: alias tunnel_1='autossh -M 20000 -N -L 8080:localhost:8080 -N -L 9200:localhost:9200 -N -L ...
Albizia's user avatar
  • 201
11 votes
2 answers
852 views

Behaviour of "eval" under "set -e" in conditional expression

Consider the commands eval false || echo ok echo also ok Ordinarily, we'd expect this to execute the false utility and, since the exit status is non-zero, to then execute echo ok and echo also ok. ...
Kusalananda's user avatar
  • 341k
2 votes
1 answer
2k views

How to execute something in current shell [duplicate]

I want to create a bash script or something similar that I can execute in the current shell: echo '#!/bin/bash export foo="bar" ' > zoom.sh but if I want to run this script in the current ...
Alexander Mills's user avatar
0 votes
1 answer
427 views

Weird behavior of su command

Everytime I run su command on this box, I constantly see the weird messages below. Switching user do eventually continue, but why are these messages showing? <Server>:~ # su - -bash: eval: line ...
Ykaly's user avatar
  • 73
1 vote
1 answer
62 views

Why does this bash idiom require eval?

Why does this produces _results=""... _results="$( grep ${_gopts[@]} )" And this produces the desired _results (list of SSHFS entries in fstab)... _results="$( eval grep ${_gopts[@]} )" The _gopts ...
DocSalvager's user avatar
  • 2,272
0 votes
1 answer
141 views

How to check "eval" command?

My code docker-machine create --driver virtualbox dev VBoxManage list vms "minikube" {9c326ed5-faf4-42fe-acda-bf3a283f1a74} "kalinew" {de6de631-0d51-4638-b967-66db463cbf05} "dev" {84a116bf-02b9-...
MikiBelavista's user avatar
2 votes
3 answers
4k views

Get return code of first piped command using eval?

I wish to execute different commands and check the return code afterwards before moving to the next steps in the script. At the same time I also wish to log the output of the executed commands to a ...
T.M's user avatar
  • 21
1 vote
1 answer
6k views

Trying to export a path from inside a bash script [duplicate]

I am trying to put my whole environment set up into a single bash file. I am only hitting one issue. When I try to export a new path from inside the file it is not setting the path in the environment ...
Keith's user avatar
  • 133
0 votes
2 answers
2k views

eval ssh command in variable

I am trying to execute commands via ssh remotely. But I have the calling command saved as variable such as: SSH_CMD="ssh -i path_to/identity" SSH_USER=user SSH_DST=server dir1=dir1 dir2=dir2 now if ...
atapaka's user avatar
  • 641
5 votes
1 answer
5k views

File with parentheses/brackets in working directory causes eval error

I encountered a strange bug today, when running a script in a directory containing a directory with parentheses in it, such as a(). Minimal working example I managed to reduce the bug to the ...
KIAaze's user avatar
  • 797
-3 votes
2 answers
173 views

Loop through filenames without eval [closed]

In a shell script, if we want to loop over certain filenames, which we would get by shell globbing, as for example all MKV-files in all sub-directories starting with string "Example" – how can we do ...
viuser's user avatar
  • 2,634
1 vote
2 answers
3k views

Eval and exec with variable substitution

I'd like to execute a statement to start a server. For that I have an environment variable to determine which server is to be started. I was given this command as a starting point: eval "exec ...
Felix's user avatar
  • 123
2 votes
2 answers
802 views

Bash: How to kill eval if the process that receives its output terminates

I have a little ugly bash script on my Ubuntu machine that contains the lines: search_command="find -L $(printf "%q" "$search_folder") \( ! -regex '.*/\..*/..*' \) -mindepth 1 2> /dev/null" for i ...
Bananach's user avatar
  • 455
1 vote
1 answer
3k views

dollar sign inside eval string in bash

I have hundreds of sub-directories which contain a dollar sign (i.e., $) as the 1st character in their names, each of which needs to be visited. These sub-directories can not be renamed. The bash ...
BazukaJoe's user avatar
1 vote
1 answer
645 views

zsh: A prefix function that runs the rest of the line with no alias expansion

I am thinking of: function noalias() { setopt localoptions noexpandalias "$@" } But I don't know what the last line should be. eval "${*:q}"? eval "$@"? eval "${@:q}"? "${@:q}"? ${@:q}? $@? (...
HappyFace's user avatar
  • 1,630
2 votes
2 answers
2k views

Does `eval` apply the shell to the redirection part of the following command?

When use eval on a command, does eval apply the shell twice to the redirection part of the command? Suppose the filename in the redirection contains a whitespace, if eval applies all the steps of ...
Tim's user avatar
  • 104k
3 votes
2 answers
6k views

Why is eval not working with command substitution? [closed]

I have this command $("${DIR}/test.py" "$1") the output of which is export SOME_VAR="hello world" export ANOTHER_VAR="hello" But eval $("${DIR}/test.py" "$1") seems to do nothing. What am I ...
masterpiece's user avatar
6 votes
1 answer
3k views

eval vs. pipe through bash

What is the difference between using: eval 'echo "foo"' and echo 'echo "foo"' | bash is there any?
Alexander Mills's user avatar
-3 votes
1 answer
328 views

Eval not working

i try run this code to get random number but eval seems not working this is my code #!/bin/bash # Sequencia alfanumerica de 12 carateres aleatoriamente (maiusculas e minusculas) file="/home/...
helpme123's user avatar