How to use script output as input arguments Linux shell script [closed] - shell

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have two shell script files: "script1.sh" and "script2.sh".
Running "script1.sh" results in echo two strings.(e.g. str1 str2).
I want this "script1.sh" output (str1 and str2) to be used as the input arguments for the 2nd script, "script2.sh".
(i.e. To be equivalent to ./script2.sh str1 str2)
How can I do it?
Thanks.

Try this:
./script1.sh | xargs ./script2.sh.
This will take your output of ./script1.sh (i.e. str1 str2), split it by space and pass it to ./script2.sh as arguments.

Related

How to run "jobs" command in shell script? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I created the file test.sh which contains ls -ltr & jobs command. When I run it, it gives me the output of ls -ltr, but for jobs command it doesn't give me anything, not even an error.4
Whats wrong?
jobs is an interactive command -- it is not meant to be used from scripts, and doesn't do anything useful in a script (but it could plausibly do something useful in a shell function called from an interactive session; so disabling it in code isn't really appropriate, either).
To keep track of background jobs, collect their PID:s when you start them.
ls -ltr &
pid=$!
printf 'pid: %s' "$pid"

Different results for same argument for different Unix functions [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am getting somewhat different results with using these commands:
ls "$MYDIR/*.avi"
md5sum "$MYDIR/*.avi"
using win-bash. The former lists only the files that end with .avi while the latter does the checksum calculation for all files containing .avi. Is this expected? I thought the wildcard operation should work the same throughout.
Because you're quoting the wildcard, it is not being expanded by the shell (but the variable is). That means you're letting the command decide what to do with the * character.
You want the shell to expand the filenames before invoking the command:
ls "$MYDIR"/*.avi
md5sum "$MYDIR"/*.avi
You might want to store the results in an array if you're reusing them
files=( "$MYDIR"/*.avi )
ls "${files[#]}"
md5sum "${files[#]}"

Shell script with variables [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm working a shell script to admin out email system. Essentially I get the users info and grep it to get the data I need. I've ran the below commands in terminal and they work as intended but when I use the below script I get an error "Command not found". I think its trying to run the 3rd line as a command. Anyone know what could be the problem here?
read -p "Enter email address to remove from groups: " purge_email
purge=$(python /gam/gam.py info user $purge_email)
purge_chunk=$($purge | grep -A 100 "Groups:")
echo $purge_chunk
Try:
purge_chunk=$("$purge" | grep -A 100 Groups:)
the $purge should be evaluated as formatted output the way gam kicks it out in a txt file or .csv you would use as a data source for a gam script in bash.

Inserting arguments as part of another argument in bash alias or function [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'd like to make a bash function (or alias) like:
function warmup() { ab -n100 http://$1.myapp.appspot.com/ ;}
But I get:
$ warmup some_version
ab -n 1000 -c 5 http://.myapp.appspot.com/ some_version
What am I doing wrong? Is this possible?
It works for me in bash 4.2.10, it might not work on an older version. Try upgrading yours.

bash-script-automatically [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I wrote the following script:
#!/bin/bash
./vlc $nom > $fichier
gedit $fichier
In the execution of my script. The first command (. / vlc $ name> $ file) runs but once the video is playing. The second command is not executed.
For that the second command runs, I would have to return to the console and I do: Ctrl+C
I would like everything is done automatically.
You have any idea please?
Maybe what you want is for the first program to run in the background:
./vlc $nom > $fichier &
gedit $fichier

Resources