Questions tagged [exec]

The exec() family of functions replaces the current process image with a new process image, retaining the pid and pipes of the old process. This tag is also used for the shell built-in which can be used to replace the current shell with a program or various redirection-related stuff.

Filter by
Sorted by
Tagged with
5
votes
3answers
5k views

Does running “exec echo some; echo test” in bash never print “some test”?

Does running exec echo "some "; echo "test" in bash never print "some test"? I would seek confirmation to this question, as I am writing a small shell script and I would like it to not contiue ...
3
votes
5answers
1k views

Fastest way to determine if shebang is present

If I have a file with #!/usr/bin/env foobar what is the fastest/best way to determine if this file has a hashbang? I hear you can just read the first 2 bytes? How?
1
vote
1answer
321 views

Change the default executable for file with potentially missing shebang

I have a library - users are to create executable files, potentially with a hashbang to tell exec which executable to use. If they omit the hashbang, then I think most systems default to /bin/sh, I ...
0
votes
3answers
201 views

Trying to add multiple grep commands within an exec

I am trying to search all files in a directory (and all subdirectories) for a string. If the file has that string, I then want to search for the number of times another string occurs, in this case "...
9
votes
4answers
5k views

When to call fork() and exec() by themselves?

I'm learning about fork() and exec() commands. It seems like fork() and exec() are usually called together. (fork() creates a new child process, and exec() replaces the current process image with a ...
-1
votes
3answers
40 views

How to find and execute all “uninstall” normal files?

I have a couple of uninstall files. I want to find all of them and execute them one by one. I know about find and exec combination so I tried find . -name uninstall -exec {}\; But this gives me such ...
0
votes
2answers
151 views

find: current filename evaluates to empty in nested command

I am trying to rename a bunch of images in a directory according to their dimensions. To that end, I am building up my command step by step, using of Imagemagik's identify command. I currently am ...
1
vote
1answer
696 views

A cron job forks/exec()s before terminating. What happens to the stdout of the child?

Normally, a cron job's stdout and stderr are e-mailed to me (as per the MAILTO setting in crontab) when the job finishes. What if my job starts another job with fork/exec (or just plain exec) or with ...
9
votes
2answers
2k views

What's the purpose of the execute permission?

Suppose setuid/setgid bits are of no concern. Why is there a separate permission for execution? Philosophically, it feels to me that the write permission subsumes the read permission, and that the ...
2
votes
2answers
2k views

How to copy standard output and standard error to the log?

I need to write the standard err and standard output to $LOG, while also having them printed on console, from within a script. The script has many commands, so redirecting each one of them is not a ...
-2
votes
1answer
719 views

The zeroth argument to a command executed by exec [closed]

From Bash Manual exec [-cl] [-a name] [command [arguments]] If command is supplied, it replaces the shell without creating a new process. If the -l option is supplied, the shell places a ...
2
votes
2answers
4k views

Get rid of “connection refused” error in bash script

I have this line: exec 3<>/dev/tcp/127.0.0.1/9091 > /dev/null 2>&1 || { PORT_IS_FREE="yes"; }; which is checking if port 9091 is available. If a connection cannot be made, then I ...
11
votes
1answer
5k views

What does & do in the middle of “exec &>/dev/null”?

My command is: exec &>/dev/null What does this & and full command do here? I know it is being redirected to the bit-bucket.
3
votes
1answer
790 views

exec with a variable filedescriptor

Why isn't this possible and what's the best way around it: #!/bin/sh desc=5; file=/etc/passwd exec "$desc"<"$file" #the variable filedescriptor is the problem I'd rather not eval.
0
votes
0answers
98 views

How to simulate existence of file to a particular process

Suppose I'm a user with no root rights on non-lsb Linux machine, where there is no /usr/bin/env. I would like to be able to call scripts that I download just as they are, to avoid editing them. Can I ...
0
votes
1answer
2k views

How do I touch every file in a directory? [duplicate]

I'm using Amazon Linux with bash shell. I'm trying to touch every file in a certain directory, but this command is failing: [myuser@mymachine scripts]$ find /usr/java/jboss/standalone/deployments/...
1
vote
1answer
970 views

The differences between sed #, %, / and |

I'm trying to replace a string in database. I found the possible solutions below. Using # or % works to me, but not for / and |. Can anyone explain why the first two works and what the differences are ...
17
votes
6answers
6k views

Choose interpreter after script start e.g. if/else inside hashbang

Is there any way to dynamically choose the interpreter that's executing a script? I have a script that I'm running on two different systems, and the interpreter I want to use is located in different ...
1
vote
2answers
3k views

Pipe inside exec command won't work

I have the command in a script: exec su -s /bin/sh -c 'exec "$0" "$@" | ts "[%Y-%m-%d %H:%M:%S]"' user -- test.python $FULLPATH &> log & Where FULLPATH is the path of the test Python ...
2
votes
2answers
1k views

How can i run a program with modified argv[0] using busybox ash shell?

In bash I would simply use exec -a. How can I do this in busybox? Is it even possible, or will I have to write my own C program to call exec(3) directly?
0
votes
1answer
665 views

setarch unrecognized architecture [closed]

So I'm trying to use setarch to add the -R flag on a program, but it seems whenever I do any sort of flag I keep getting unrecognized architecture. I've done arch to figure out what bash is (x86_64) ...
2
votes
1answer
98 views

Search a bunch of gps files in a folder for final distance, output list of distances

I have a bunch of .tcx files (essentially a GPS device outputted XML file) in a folder. They follow the naming convention DATE_LOCATION_SPORT.tcx. Each file has a bunch of track-point nodes noting ...
1
vote
1answer
55 views

find dir with wildcard and run git status not working

When I run find -maxdepth 1 -type d -name 'iptp*' -execdir bash -c "ls {}" \; I get a listing of all dirs named iptp* When I run find -maxdepth 1 -type d -name 'iptp*' -execdir bash -c "git ...
0
votes
1answer
2k views

When running a daemon, how do I execute a command from a given directory?

My shell script knowledge is a little shaky, but I want to run a daemon (Ubuntu 14.04) defined in /etc/init.d/unicorn, like so case "$1" in start) check_config check_app_root ...
2
votes
1answer
1k views

Execved process not reading from stdin

I have a program A doing the following: Read 2 Bytes from input Print read input execing into program B. Program B does the following Read 2 Bytes from input Print input To make it concrete ...
9
votes
1answer
26k views

Can you remount /tmp partition to exec while live?

I have a server I need to re mount the /tmp partition to run exec. The code I want to use is: mount -o remount,exec /tmp Run the program that needs it. Than change it back. mount -o remount,...
2
votes
3answers
145 views

Is it possible to recover original environment in a POSIX shell script?

Is it possible to recover the original environment that a shell script was invoked with? I'm not trying to write a program that depends on the ability to access the original environment, I'm wondering ...
0
votes
1answer
2k views

Why does “find / -name '*.txt' | cp /junk” not work?

If I want to find any files with .txt in the name, and for every match that is found copy it into the /junk folder the following could be considered to work; find / -name "*.txt" | cp /junk but ...
1
vote
2answers
253 views

Can a pipe be used instead of exec in - find / -name “.txt” -exec cp {} /junk \; [duplicate]

If I want to find any files with .txt in the name, and for every match that is found copy it into the /junk folder, I understand I could use the following: find / -name ".txt" -exec cp {} /junk \; ...
1
vote
1answer
1k views

“No such file or directory” as error for wrong architecture [duplicate]

I'm trying to run a cross compiler on my 64 bit Ubuntu. and it results in a following error: $ ./arm-none-eabi-gcc bash: ./arm-none-eabi-gcc: No such file or directory The file is here and contains ...
2
votes
1answer
6k views

What is the execution environment where `command [arguments]` in `exec command [arguments]` runs?

From bash manual exec exec [-cl] [-a name] [command [arguments]] If command is supplied, it replaces the shell without creating a new process. If the -l option is supplied, the shell ...
0
votes
1answer
62 views

How to prevent this “replay caching” behaviour?

I have this little C89 program -- what it does, how it works, and the undefined behaviour aren't important, just that it does some long memory & math operations on just one thread: x, c, * b, m, ...
1
vote
4answers
1k views

Execute stdout results

Is there a way to actually execute results from a shell command, instead of using them as arguments to another command? For instance, I'd like to run '--version' on all executables in a folder, ...
1
vote
1answer
588 views

Bash Process Substitution in exec line, some commands stopped working

So I have a bash command using process substitution in an exec line that stopped working recently, and it boils down to this example: Contents of script.sh: #!/bin/bash ls -l "$1" >/tmp/out ...
2
votes
0answers
672 views

Socat exec script in tunnel

I am running a tunnel like this: socat TCP-LISTEN:9090,fork TCP:192.168.1.3:9090 I would like to run a script to execute code with the strings passing through the tunnel. The script does not change ...
1
vote
1answer
365 views

autoconf tried to invoke "exec -m' under bash, but -m is not a legal operand for exec

This question may really be about where to get help, rather than help for the problem itself. Please forgive the wordiness! I'm trying to build gcc to run on Win32 and produce code for AVR. I've ...
4
votes
4answers
1k views

How to execute bash (in script) with own .bash_logout file?

I want to execute bash in subshell and when user exits from subshell, I want to execute some other commands (like for saving logs to file). Something like this: run.sh: #!/bin/bash function ...
2
votes
3answers
1k views

Specifying redirection options through a variable, in an exec command

I want to be able to specify the redirection command/options via a variable (that I might set based on certain conditions, etc.). But when I run this bash script for example : REDIRECT=">>test" ...
2
votes
1answer
1k views

how best to send the output of a find + exec command to a pipeline?

I would like to understand how to correctly send the output of a find + exec command to a pipeline for further processing. i.e. how can we (1) select a group files (2) perform some operation on the ...
0
votes
2answers
41 views

Search by pattern, and copy within the same folder but with a different name

This is the folder structure: /home/user/Pictures/Vacation/Italy/Rome/photo.front.001.jpg Within the folder Rome I have many other photos, but I'm only interested in the ones that have "front" in ...
2
votes
1answer
2k views

How to `exec` process with custom env?

I'm programmatically spawning processes in bash. I need to be able to pass in arbitrary environment variables and commands. To achieve this I'm running /usr/bin/env and then calling bash -c. Sometimes ...
4
votes
1answer
4k views

Permission denied when using -exec {} ls with find command

When run following command it gives me permission denied message for all the files. find /data/code/ -name "*.jar" -exec {} ls \; find: `/data/code/project/shared/build/thirdparty/log4j-1.2.8/...
1
vote
2answers
216 views

Why does Ubuntu 16.04 execle of a specfic C# image halt after 90 seconds while others run 24X7?

I would like to find a Ubuntu Linux 16.04 systen command similar to strace to find out why my C++ program , ServiceController.exe , which [execle ("/usr/lib/mono/4.5/mono-service","/usr/lib/mono/4....
31
votes
2answers
7k views

reason for exec in wrapper scripts

I have seen wrapper script examples which in a nutshell are following: #!/bin/bash myprog=sleep echo "This is the wrapper script, it will exec "$myprog"" exec "$myprog" "$@" As seen above, they ...
2
votes
1answer
631 views

What kinds of commands can run with exec?

What kinds of commands can run with exec? For example, executable files, builtin commands, shell script, compound commands (e.g. looping, conditional branching), pipeline, command list, commands ...
13
votes
4answers
2k views

Use case / practical example for Bash' builtin exec

Consider this from the documentation of Bash' builtin exec: exec replaces the shell without creating a new process Please provide a use case / practical example. I don’t understand how this makes ...
1
vote
1answer
1k views

How to find files and act on them (find + exec)

I have downloaded about 3200 websites to the depth 2. So now I have one master folder (abc) that contains many folders, containing files for each website. So my folder abc contains 3200 folders and ...
38
votes
4answers
5k views

What exactly happens when I execute a file in my shell?

So, I thought I had a good understanding of this, but just ran a test (in response to a conversation where I disagreed with someone) and found that my understanding is flawed... In as much detail as ...
0
votes
2answers
2k views

Parent process always printing output after child

Consider the following code running under Solaris 11.3: int main(void) { pid_t pid = fork(); if (pid > 0) { printf("[%ld]: Writing from parent process\n", getpid()); } if (...
1
vote
0answers
380 views

What differences are between running a command in shell with and without `bash -c`?

What is the difference of running a command directly in a bash shell, and run it as bash -c <command> in a bash shell? The purpose of my question is that I would like to know how a command is ...