Linked Questions
11 questions linked to/from Bash -c with positional parameters
2
votes
1
answer
891
views
First argument of bash is different when parameter is passed or not [duplicate]
There are two bash usages:
$ bash -c 'echo $0'
bash
$bash -c 'echo $0' "text"
text
Why in the first case parameter $0 holds the program name but in second the first parameter?
2
votes
1
answer
2k
views
find with -exec eval of $0 [duplicate]
In the following command I would like to know why $0 was evaluated to the file found by find and not the echo command.
$ find . -type f -perm -u=x -exec bash -c '
/bin/echo $0 is the name of the ...
1
vote
1
answer
688
views
Arguments and positional parameters in `bash -c <some-command>` [duplicate]
Bash Manual says about bash -c <some-command>:
Read and execute commands from the first non-option argument after processing the options, then exit. Any remaining arguments are assigned to the
...
0
votes
0
answers
37
views
understanding bash positional arguments in "find -exec bash..." [duplicate]
I have a file named "testfile"
I launch command find -name testfile -exec bash -c 'file $0' {} \;
This command works, but find -name testfile -exec bash -c 'file $1' {} \; does not.
I always ...
55
votes
3
answers
35k
views
How to use defined function with xargs
This is my code
#!/bin/bash
showword() {
echo $1
}
echo This is a sample message | xargs -d' ' -t -n1 -P2 showword
So I have a function showword which echoes whatever string you pass as a ...
18
votes
5
answers
10k
views
Find files that contain multiple keywords anywhere in the file
I'm looking for a way to list all files in a directory that contain the full set of keywords I'm seeking, anywhere in the file.
So, the keywords need not to appear on the same line.
One way to do ...
6
votes
2
answers
4k
views
What's the `name` argument to `sh -c` for?
Taken from FreeBSD's man page on sh (because its the most convenient online, target platform is Debian if it matters):
SH(1) FreeBSD General Commands Manual SH(1)
NAME
sh -- ...
1
vote
2
answers
1k
views
Using rsync copying all certain files into one single folder - no find command
although there are many rsync examples out there, my question:
Is there a rsync only command line which copies certain file types (like. .mp3) into one single folder !without using any find command! ...
0
votes
1
answer
401
views
Using the "$@" special args in a new bash command (bash -c)
I am trying to run a bash -c command relying on the parent bash scripts arguments via "$@"
When running a normal command, I use "$@" and bash does the expand magic for each arg.
...
1
vote
0
answers
310
views
Explanation of sh-c
I am going through ,this answer here
Understanding the -exec option of `find`
I am not able to understand, how below piece of code works
sh -c 'echo "hello $1" ' somestring works
How does ...
1
vote
1
answer
136
views
Can the command within for-loop affect the iterations?
In Bash,
the syntax of the C-like for-loop is:
for (( expr1 ; expr2 ; expr3 )) ; do commands ; done
Can the execution of commands affect the evaluations of the three
arithmetic expressions expr1, ...