All Questions

Filter by
Sorted by
Tagged with
4
votes
1answer
180 views

Processes in a session in an interactive shell vs in a script

If I run this command in a script it doesn't produce output except header from the ps: # Taken from Advanced Bash Usage on youtube: echo "$(echo "$(echo "$(echo "$(ps wwf -s $$)")")")" This is ...
1
vote
1answer
46 views

Why do I have “command not found” in my script?

I am writing a Nagios plugin and I have a "command not found" when I run it. What is wrong? Why 127.0.0.1 (or localhost as well) is not recognized? When I run just the snmp request - I have a simple ...
1
vote
1answer
33 views

how to execute compound commands in shell script?

Here's my script: #!/bin/sh result=$((diff <(sort 1.txt) <(sort 2.txt))) if [[ $result != "" ]] then echo ERROR else echo PASS fi I got an error when execute this script: chk.sh: ...
0
votes
1answer
61 views

Why value of a is 1?

I'm learning shell scripting and I am writing a script which lists the file for which the user has "7" permission, i.e. "rwx". So far I've written this: for F in * do a= $(stat -c "%a" "$F") ...
0
votes
1answer
45 views

Find in command substitution: Empty result inside while, result in command line

I have this bash script to find files recovered by PhotoRec (files I know are there, but because of their number I can't locate them one by one), but the find command doesn't return any results, if I ...
1
vote
2answers
693 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 ...
1
vote
2answers
44 views

Pass length of argument into bash command substitution

I'm trying to write a quick bash function that populates a README.md with a $1\n followed by underscores the length of $1. The code I found in other stackexchange questions showed that to print a ...
3
votes
2answers
297 views

Bash parameter substituiton within commands

I have a passing understanding of Parameter Substitution, including substrings like so foo="Hello World"; greeting=${foo:0:6} But do I do this with commands? greeting="Hello" md5greeting=$(echo $...
4
votes
2answers
2k views

Checking results of a command in Bash script

I am reading "Advanced Bash-Scripting Guide" at the moment. There is some script that not working correctly on my machine: HNAME=news-15.net # Notorious spammer. # HNAME=$HOST # Debug: test for ...
2
votes
2answers
146 views

Shell Command Substitution Difference/Anomaly

When scripting in Bash, we learned to assign a variable to the output of a command, we can use the construct: variable=$(command-string) This is known as command substitution and executes the ...
0
votes
1answer
17 views

Unable to resolve $proc_date from the script

I have multiple HQL's, below is the one example. located at : /home/ganesh/CopyJobs/hql/ insert into XYZ.exttbl_form_data PARTITION (load_date="$proc_date") select FORM_DATA_ID,FORM_ID,USER_ID,...
0
votes
1answer
1k views

Concalc - “tcsetattr error: Inappropriate ioctl for device”

In a bash script I use the following: #!/bin/bash calc=$(concalc "$*") printf "%s\n" "$calc" I do get the result I want, but allways with this error message: tcsetattr error: Inappropriate ioctl ...
4
votes
1answer
192 views

escaping a dollar in a command?

I have a very simple shell script that should remove floating docker images, the command for this is: docker rmi $(docker images -f "dangling=true" -q) Now I'm running into an issue which I think is ...
2
votes
1answer
2k views

Getting no output from command substitution?

I've written a few shell scripts, but have never seen this behavior and am at a loss. I've got the following simple script which runs in a bash shell: LOGFILE="/var/log/constructor-events.txt" ...
1
vote
1answer
47 views

How to set an alias upon command execution?

I want other developers to have some convenient methods. Therefore I want to give them a script, that automatically sets an alias. E.g the command grunt compileModule:[modulename] should set the ...
0
votes
2answers
1k views

Makefile, sqare brackets built-in, variable expansion and command substitution

To embrace the DRY (Don’t Repeat Yourself) principle, I sometimes need to share pieces of shell commands in a Makefile. So there is a recipe somewhere in that file like: shell=/bin/bash # … .ONESHELL:...
0
votes
2answers
688 views

Why the remote ls from here doc from ssh does not work within a $()? [duplicate]

I am trying to count the number of files in a remote directory. I have the following code: ssh server.com<<RUNTHIS FILE_COUNT=$(ls -AU /foo/bar/test_dir) echo "$FILE_COUNT" > ~/...
2
votes
1answer
95 views

Why is the IFS value removed from the file while splitting?

IFS=$'?\n' for line in $(cat "./newfiletoread") do printf "${line}\n" done The file contents are as below: Hello there!How are you doing?How is life?Mine is as boring as a winter morning! The code ...
1
vote
1answer
47 views

Extracting parts of whitespace separated string

I have several Git repositories containing a file mergedriver.info This file looks always like this: <project name> <repository name> A script, triggered by a Git merge driver, is ...
4
votes
1answer
2k views

Find a file and make a symlink to parent using find and -exec

I am trying to use find to find files matching a certain pattern, and then symlink their parent directorys to another directory, this is my current script (I'm doing this on mac so -printf won't work ...
0
votes
1answer
91 views

netcat pipe running too early?

I have the following script running in the background: while true; do { file=$(/somescript); echo -ne "HTTP/1.0 200 OK\r\n\r\n"; cat $file; } | nc -l -p 20000 done It works fine, except that /...
0
votes
3answers
589 views

issue with back quotes inside while loop when running a command over ssh

This question is a bit complicated. I will try to explain in detail. I have two machines, one is local and other say 192.168.1.2. I have set the following variables in my local machine CHECK="/home/...
-1
votes
2answers
123 views

How to avoid a variable containing a list of directories being treated as string [closed]

#!/bin/bash Dir='/home/TEST' Project="${Dir}/Project.txt" The text file Project.txt contains the file type & its path: SOURCE|FILE|TARGET_PATH TEST|BDL|/LOAN/NDL/XML TEST|BDL|/LOAN/DL/XML TEST|...
9
votes
1answer
6k views

Can I get the exit code from a sub shell launched with $(command)? [duplicate]

I am setting a variable like this: myvar=$(command --params) I want to check the exit code ($?) of my command afterwards. Checking $? like this always returns 0 because it successfully set the ...
20
votes
1answer
1k views

What does POSIX require for quoted here documents inside command substitution?

In this question someone reports a problem using a here document with a quoted delimiter word inside $(...) command substitution, where a backslash \ at the end of a line inside the document triggers ...
4
votes
1answer
612 views

Access variables set inside command substitutions

I wrote a simple script #!/bin/bash -x selentry=`ls -l / | sort ; ts=${PIPESTATUS[0]}` echo $ts but $ts show nothing. How I can display $ts variable, or how I can get exit status code from ...
0
votes
1answer
144 views

shell script run by xautolock keeps stall value in command substitution

I'm trying to make a simple script to put my computer to sleep if it runs on battery unattended. I have this simple script: #!/bin/sh if [ `cat /sys/class/power_supply/ADP1/online` -eq 0 ]; then ...
1
vote
2answers
1k views

move subshell output into an array in bash 3

How do I import the results of a subshell command into an array in bash 3? I have been using mapfile to accomplish this in bash 4 as follows: mapfile -t myarray < <(someScript.sh) However, ...
3
votes
2answers
2k views

Command works at the command-line, but won't work in a shell script [duplicate]

I am creating a script and when I try to capture a command return, I have an error of command not found, if I use this command on the terminal: gcloud -q compute snapshots list --format='csv(NAME)' ...
1
vote
2answers
521 views

Quoting the output of a backtick command [duplicate]

I'm trying to run an expect script that runs a telnet session to automate the sending of an email, I'm trying to pass the contents of a file as a single argument to my script but when the backticks ...
1
vote
1answer
651 views

Assign continuous stream to variable and process the variable

I'm trying to make an analyzer for a custom log that I have. My log file has a duration timestamp (in ms) which I want to filter out from the others and send me the logs that take over a threshold ...
0
votes
1answer
102 views

Writing output of command to variable [closed]

I would like to put the output of a command into a variable. As far as I know, you have to use either of these: variable=$(command) variable=`command` The following should work from my point of view:...
-4
votes
1answer
357 views

Back Tick version of this command [closed]

TAROUTPUT=$(tar cvf /tmp/incremental_backup . tar $(find /etc -type f -mtime -1)) Please suggest how can i use backtick for above command
1
vote
1answer
142 views

Output broken when appending output of sql query in ksh

I'm very new to scripting. I would like to add the output of the sql function given below to another variable for example: month_end () { mdate=$($SQLPLUS_HOME/sqlplus.exe -S $DBC << END set ...
1
vote
1answer
102 views

Substitute with `…` multiline output of find command [duplicate]

I need to substitute output of find command to another command to process every found file, e.g.: mdls `find ~/target_dir/ -iname '*some*' -depth 1` (mdls is a command in OS X which get metadata ...
1
vote
1answer
548 views

How to escape a range of wildcards in unix shell script?

I need to execute the following Oracle SQL in unix crontab. The query is as follows: select count(*) from tbaadm.htd where cust_id is not null and pstd_flg = 'Y' and del_flg = 'N' and tran_date = (...
1
vote
2answers
237 views

How do I create a rule for custom flag replacement with C shell?

I want to have the following behavior with grep: grep --java <rest of the command> Where --java would either dynamically convert to --include=*.java or internally be equivalent to it. Is there ...
-1
votes
2answers
4k views

Nested echo command in backticks

I want to know why an extra echo will print in my shell. I'm using bash version 4.2.46(1). echo `echo `echo $SHELL`` A interesting issue is if I replace '``' with $() it doesn't print extra echo: ...
6
votes
3answers
2k views

How to prevent bash command substitution output from being escaped?

I am trying to use command substitution in a bash script to output redirection symbols based on a variable like so: IS_VERBOSE=false curl $BLAH $( $IS_VERBOSE && echo '-i' || echo '> /dev/...
2
votes
4answers
468 views

slicing different words from output

Suppose, the result of a command in linux shell is as follows: X and Y are friends Is there any way to slice each of the words (X, and, Y, are, friends) or the first n words from the result, so that ...
21
votes
1answer
742 views

Why won't function return until background process ends?

Consider this script: #!/bin/bash function start { leafpad & echo $! } PID=$(start) echo "PID is $PID" The script does not continue past its closing brace until the leafpad process ends, ...
6
votes
2answers
16k views

Bash script error: integer expression expected

I have a problem with a bash script on raspberry pi: x='gpio -g read 22' if [ $x -ge 1 ] then gpio -g write 23 1 fi The error is integer expression expected. Why?
1
vote
1answer
164 views

Calculate swap values dynamically

Can someone please let me know if the following commands should work as I am not sure and am getting error? Just to let you know that I am using this in one of my nagios scripts: ## GET SWAP Warning ...
7
votes
2answers
2k views

Difference of using () and $() to execute a series of commands

I am currently trying to make a script that creates bytes that will be piped as input to netcat. Here is the idea of the script: (perl -e "print \"$BYTES\x00\"; cat file; perl -e "print \"More ...
4
votes
2answers
4k views

Simultaneously check for empty output and successful exit status

I'd like to write the following test in an installer script1: if [ -n "`/etc/grub.d/30_os-prober`" ]; then install_dual_boot else install_linux_only fi However, it's also possible that 30_os-...
1
vote
5answers
7k views

Output to variable with an indirect command (eval)

What is wrong with this indirect command when run with eval ? #!/bin/bash OS=AIX host=myhost CMD_AIX="(o=\`host \"$host\" \`)" CMD=\$CMD_$OS echo $CMD eval echo $CMD eval "$CMD" Ouput: $ ...
1
vote
2answers
2k views

Apply a filter to the value of a variable using backticks

Sorry for asking such a simple question, but reading about this issue on the internet has proven fruitless. I'm trying to better understand the grave/backtick operator and I've been doing okay so far ...
1
vote
1answer
734 views

How do I capture output into a variable and still have it goto the screen too?

I can do OUTPUT=$(grunt test) and that puts the output into OUTPUT but it's no longer on the screen. I need to see the output as it comes as well, so I can't just wait and then echo $OUTPUT. How can ...
4
votes
1answer
292 views

cmd2 `cmd1` vs cmd1 | xargs cmd2

I'm trying to find a file with find and then pass the found path to sqlite3. I'm only dropped into the sqlite> prompt if my command is of the form: sqlite3 `find . -type f -iname "*.db" | head -n1`...
0
votes
2answers
901 views

Bash Mysql Command Substitution Login Failure

Bash and MySQL versions: GNU bash, version 4.2.25(1)-release (x86_64-pc-linux-gnu) mysql Ver 14.14 Distrib 5.5.37, for debian-linux-gnu (x86_64) using readline 6.2 I have a bash script that tries ...