How to pass string command to shell pipe to execute it (output of awk)


bow

For example this works:

echo 1 // output: 1

This doesn't work:

'echo 1' | "/bin/sh" // output: echo 1: command not found

Why is the string because I have the output of awk and I need to pass the string to execute some commands like this:

awk '{ print 'chmod 755 "$0"' | "/bin/sh"}' file.txt

I need to use a string like this because I guess it will allow me to put the parameters where I want in the command.

So I first wanted to try executing it manually from bash and see if it worked before putting it into the awk print command.

steel knife

You are passing a string to the shell - but the string you are passing is1

To pass echo 1you need something like

echo 'echo 1' | /bin/sh

or

printf '%s' 'echo 1' | /bin/sh

(outside of awkwhich you don't need citations /bin/sh).

Related


Pipe command output to Awk

Joint venture I want to pipe the output of a command to awk. I want to add that number to each row in a new column in an existing .txt file. The new column should be at the end, not necessarily the second column. $ command 1 4512438 $ input.txt A B C D $ req

Pipe command output to Awk

Joint venture I want to pipe the output of a command to awk. I want to add that number to each row in a new column in an existing .txt file. The new column should be at the end, not necessarily the second column. $ command 1 4512438 $ input.txt A B C D $ req

Pipe command output to Awk

Joint venture I want to pipe the output of a command to awk. I want to add that number to each row in a new column in an existing .txt file. The new column should be at the end, not necessarily the second column. $ command 1 4512438 $ input.txt A B C D $ req

Pipe command output to Awk

Joint venture I want to pipe the output of a command to awk. I want to add that number to each row in a new column in an existing .txt file. The new column should be at the end, not necessarily the second column. $ command 1 4512438 $ input.txt A B C D $ req

Pipe command output to Awk

Joint venture I want to pipe the output of a command to awk. I want to add that number to each row in a new column in an existing .txt file. The new column should be at the end, not necessarily the second column. $ command 1 4512438 $ input.txt A B C D $ req

How to pass variables from awk to shell command?

Vahid Mirjalili I'm trying to run a shell command from awk for each line of a file that requires an input parameter. I tried to use system()but the input parameter is not recognized. Each line of this file is the address of a file that I want to run a command

How to pass variables from awk to shell command?

Vahid Mirjalili I'm trying to run a shell command from awk for each line of a file that requires an input parameter. I tried to use system()but the input parameter is not recognized. Each line of this file is the address of a file that I want to run a command

gulp: how to execute a shell command and get the output

Li Gangyu I need to run a shell command and write the result to a json file: const Shell = require('gulp-shell'); gulp.task('build-info', () => { gulp.src('./app/_bundle_info_.json') .pipe(jeditor((json) => { var buildNumber = Shell.task([

gulp: how to execute a shell command and get the output

Li Gangyu I need to run a shell command and write the result to a json file: const Shell = require('gulp-shell'); gulp.task('build-info', () => { gulp.src('./app/_bundle_info_.json') .pipe(jeditor((json) => { var buildNumber = Shell.task([

gulp: how to execute a shell command and get the output

Li Gangyu I need to run a shell command and write the result to a json file: const Shell = require('gulp-shell'); gulp.task('build-info', () => { gulp.src('./app/_bundle_info_.json') .pipe(jeditor((json) => { var buildNumber = Shell.task([

gulp: how to execute a shell command and get the output

Li Gangyu I need to run a shell command and write the result to a json file: const Shell = require('gulp-shell'); gulp.task('build-info', () => { gulp.src('./app/_bundle_info_.json') .pipe(jeditor((json) => { var buildNumber = Shell.task([

gulp: how to execute a shell command and get the output

Li Gangyu I need to run a shell command and write the result to a json file: const Shell = require('gulp-shell'); gulp.task('build-info', () => { gulp.src('./app/_bundle_info_.json') .pipe(jeditor((json) => { var buildNumber = Shell.task([

Execute command on shell command output

Salt I have a command that will run forever and output something periodically until it is killed by something else (something like that tail -f), and I want to make it so that whenever there is new output, another command will be executed. Precautions: I can't

Execute command on shell command output

Salt I have a command that will run forever and output something periodically until it is killed by something else (something like that tail -f), and I want to make it so that whenever there is new output, another command will be executed. Precautions: I can't

How can I pipe command output to a CSV file in the shell?

Reynolds Singh ~]$ date;daemon -ip stats| bytes Fri Jun 22 13:58:37 +08 2018 1958391001 transmit bytes 1825330799 receive bytes I want to pipe these values to the CSV file mentioned below. what should I do? |date| bytes sent|bytes received| Mark Sechel like t

How to get Jsch Shell command output in a string

A bit: I'm using the JSCH -SSH library to execute commands in a "shell" channel and I can't find a way to find both ways: 1) How can I find out if a command is fully executed on the remote unix box? 2) How to capture command output in String instead of printin

How to get Jsch Shell command output in a string

A bit: I'm using the JSCH -SSH library to execute commands in a "shell" channel, but I can't find a way to find both ways: 1) How can I find out if a command is fully executed on the remote unix box? 2) How to capture command output in String instead of printi

How to compare command output to string in shell script

Deroca I've been struggling to figure out how to compare the output of a command stored in a variable with the contents of another variable (also a string) in Shell Script. I know this looks like a basic RTFM case, but I've done it, but I really can't figure i

How to get jsch shell command output in string

slimy I'm using the JSCH -SSH library to execute commands in a "shell" channel, but I can't find a way to find both ways: 1) How can I find out if a command is fully executed on the remote unix box? 2) How to capture command output in String instead of printin

How to convert command output to string in shell script

user 468587 In my script I need to loop through the lines in the file, once I find some specific line I need to save it as a variable so I can use it later outside the loop, I tried the following but it doesn't work: count=0 res="" python my.py -p 12345 | wh

How to get Jsch Shell command output in a string

A bit: I'm using the JSCH -SSH library to execute commands in a "shell" channel, but I can't find a way to find both ways: 1) How can I find out if a command is fully executed on the remote unix box? 2) How to capture command output in String instead of printi

How to convert command output to string in shell script

user 468587 In my script I need to loop through the lines in the file, once I find some specific line I need to save it as a variable so I can use it later outside the loop, I tried the following but it doesn't work: count=0 res="" python my.py -p 12345 | wh