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
0 votes
1 answer
63 views

How is this exec command supposed to work in this context?

I'm working through a textbook on UNIX system administration. Chapter 3 of "Unix Third Edition" by a Syed Mansoor. Chapter 13 has the following example of exec usage which is straightforward ...
Anthony De Vellis's user avatar
0 votes
1 answer
51 views

how to bring exec $@ process in foreground

I want to know how docker entry point process which has started with exec $@ and has PID 1 how to bring that in foreground I tried exec $@ & but its not working, My use case: I want to terminate ...
Samurai's user avatar
  • 55
0 votes
2 answers
76 views

missing argument to `-exec' error when executing Shell script but runs fine on command lines

I have this Shell script here: ### # Create a folder dynamically mkdir archived_PA_"$(date -d "6 months ago - 1 day" +%Y-%m-%d)"_"$(date -d "1 day ago" +%Y-%m-%d)&...
Anna Nguyen's user avatar
1 vote
1 answer
32 views

How to load android binaries in Debian environment?

I am trying to run adbd from within a chrooted environment. I can run it fine with Android's LD_LIBRARY_PATH=$PWD ./linker64 $PWD/adbd. When I try to run ./adbd I get: bash: ./adbd: cannot execute: ...
Bret Joseph's user avatar
1 vote
0 answers
26 views

Why does subcommand take the PID of parent when I don't use exec [duplicate]

I executed bash -c "ps && ps" and got the following output: PID TTY TIME CMD 25544 pts/0 00:00:00 bash 26562 pts/0 00:00:00 bash 26563 pts/0 00:00:00 ps PID TTY ...
user1335014's user avatar
1 vote
1 answer
46 views

How to display file and folder properties from search

I thought this would be easy and there are a lot of somewhat close threads on the internet, but nothing quite right. I want to use fd (simple find command) to display just file name and file size (...
1toneboy's user avatar
  • 103
1 vote
2 answers
148 views

Capture and redirect stdin (user input) for runtime of script

I can redirect the stdout/stderr of everything in a script like this: #!/bin/bash exec > stdout_file echo example But now I want the stdin of the whole script to be written into a file. I tried it ...
Nudin's user avatar
  • 111
1 vote
1 answer
94 views

Log all commands executed regardless of shell?

Suppose a user runs the following command: zcat file.gz | grep something | gzip > grepped.gz I'm looking for a kernel feature (a BPF filter perhaps?) that would note all of the execves, chain ...
d33tah's user avatar
  • 1,361
-1 votes
1 answer
48 views

Why 'helix-23.03-aarch64.AppImage' [in debian on x86_64 in Macbook Pro] is giving 'Exec format error'?

It is on debian on x86_64 me@debian:~/bin$ chmod a+x helix-23.03-aarch64.AppImage me@debian:~/bin$ ./helix-23.03-aarch64.AppImage /tmp/.mount_helix-RyzFyw/AppRun: 4: exec: /tmp/.mount_helix-RyzFyw/usr/...
tom_kp's user avatar
  • 33
0 votes
3 answers
82 views

bash -c "exec -a myProcessName ./script.sh &" doesn't send that script into backgound

From a bash script, I need to start three processes and put to each of these processes a name, in order to be able to stop them in a later stop command. # Démarrer les applications eco emploi : ...
Marc Le Bihan's user avatar
2 votes
1 answer
154 views

Why does the provided command as a parameter not run in a loop in my script?

I made a simple script that executed a command every minute: #!/usr/bin/env sh while true; do exec "$@" sleep 60 done The idea is to make it as a Docker entrypoint that will allow ...
Dimitrios Desyllas's user avatar
0 votes
1 answer
314 views

Does running exec command preserves environment variables of the calling shell? If so, why?

From my understanding exec command replaces the calling shell program with the command without forking a child process. Also if I understand correctly exported variables are the ones that are passed ...
Almaz Kharrasov's user avatar
0 votes
1 answer
152 views

Help with -maxdepth in 'find -exec mv' command line

I'm working on a sorting/filtering cron script to process incoming files based on a set of constant strings (logfile, history, dataset, etc). The files to be sorted all sit under a common folder, some ...
graphics.guy's user avatar
0 votes
1 answer
239 views

"exec" is exiting the script and not proceeding to next step

We are trying to capture return code of exec command but once the command is executed the script is getting exit without proceeding to next lines. exec /bin/sh -c $command > log.txt rc=$? if [ $rc -...
Arya's user avatar
  • 306
0 votes
0 answers
27 views

How to set the Exec when bash command is too long?

The desktop file works fine: [Desktop Entry] Type=Action Name=unrar zip or rar file Profiles=unrar [X-Action-Profile unrar] MimeTypes=inode/directory Exec=bash -c "unar /home/test.rar -o /tmp;...
newview's user avatar
  • 205
1 vote
2 answers
308 views

Redirecting stderr to temporary fd in a Bash script

I see that many questions have been asked and answered on SE about redirections in Bash using exec, but none seem to answer my question. What I'm trying to accomplish is redirect all output to stderr ...
mesr's user avatar
  • 167
2 votes
1 answer
48 views

How do I insert my own lib to other binaries in Linux?

My goal is developing a tool for educational purposes which logs commands on a system. Until now have found primitive ways to do this but all these ways can be easily bypassed so I had this idea to ...
Jugert Mucoimaj's user avatar
0 votes
4 answers
286 views

execute a command recursively on the files of a folder in the matching location, not in the original one

I want to recursively convert files from .docx to .doc in a folder. The problem is that all the output files are created in the folder where I run the following command, not in the location of the ...
fich's user avatar
  • 290
1 vote
1 answer
246 views

Is it possible to load up a binary into ram, without executing it?

Like I will use google chrome whenever I use linux (most probably) But I don't want it to auto start when ever I open it. I could open it manually, but I have HDD so it is pain to load for the first ...
Afroz Alam's user avatar
3 votes
1 answer
376 views

Signal handling in shell script with exec and pipe to filter output with grep

I'm deploying a containerized application which outputs an enormous amount of useless messages on startup (the same message for about a million times, without any variation). The message cannot be ...
Namoshek's user avatar
  • 133
1 vote
1 answer
1k views

Need to capture exit code of pylint command using find in Github actions

I am trying to implement a python linter using pylint. But I am getting the score of each python file and also displaying the suggestion to improve the score but I am also looking to terminate the ...
sidharth vijayakumar's user avatar
3 votes
3 answers
1k views

How to print to stdout after exec >/dev/null

In a script, I have a long list of commands that print to stdout. I want to hide all output. So instead of redirecting each command, I put exec >/dev/null at the beginning. What options do I have ...
finefoot's user avatar
  • 2,960
2 votes
0 answers
36 views

Why does the exec redirection disturb / interrupt a pipe to jq? [duplicate]

This is the reduced version of my script: # parse json echo '[{"foo":"bar"}]' | jq # log output to file and stdout exec &> >(tee -a "/tmp/test.log") # parse ...
mgutt's user avatar
  • 377
0 votes
1 answer
129 views

Why basename don't work here [duplicate]

Why when I do this (I know, it's stupid) it returns the full path, not only the filename as expected? ls -l | awk '{print $9}' | xargs -I% find ./my_dir -type f -name "%" -exec echo $(...
Alysko's user avatar
  • 103
0 votes
0 answers
704 views

The total size of the argument list and exported variables exceeds the OS limit of 1MB

I was doing a grid search for some scientific computing project, and got a bunch of log files with parameters embedded in the filenames. $ ls -l | wc -l 38210 $ ls -l | tail -rw-rw-r-- 1 qys ...
nalzok's user avatar
  • 369
0 votes
1 answer
138 views

Working with file descriptors in the (bash) shell?

I came across the following set of shell commands for reading and writing to serial ports, from this thread: stty -speed 19200 < /dev/ttyS0 # sets the speed of the port exec 99<>/dev/ttyS0 (...
First User's user avatar
0 votes
2 answers
97 views

What happens to the file structs of processes after execve

If I understand the man pages correctly, the fd table of a process that forks and execves are copied to the the child process and survive the execve. On the other hand, any other memory mapping is ...
Manouil's user avatar
0 votes
0 answers
118 views

exec terminate command by the space in single quotes

I have a simple bash script goes like #!/bin/bash set -e SPARK_CONF="--master ... \ ... --conf spark.driver.extraJavaOptions='-verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps' \ --conf ....&...
Alain ux's user avatar
0 votes
0 answers
28 views

pass output as grep pattern [duplicate]

I wish to pass each line of a file as a grep pattern to be searched in data.txt file. Thus, i need cat allsearchstrings.txt | grep <should be lines of allsearchstrings.txt> data.txt cat ...
Ashar's user avatar
  • 459
0 votes
1 answer
763 views

`exec env` vs `env`

Both exec and env don't fork, see the following example: docker run --rm -it ubuntu:18.04 sh -c 'exec sleep 1 & ps -Ho pid,ppid,cmd' PID PPID CMD 1 0 sh -c exec sleep 1 & ps -Ho ...
Weihang Jian's user avatar
  • 1,159
3 votes
1 answer
376 views

Output to variable or file using (find with -exec and shred)

I have a find command that I exec to shred and it works great; however, I need to capture the output of this and pass to a variable or a file. I have tried so many iterations of the below commands, ...
John Riordan's user avatar
1 vote
2 answers
10k views

How to launch application with rofi using i3wm's exec?

I had this issue and now I know how to solve it. I need to launch applications with i3wm's exec command. ButI use rofi as launchmenu and I have no idea how to make it lauch applications with i3wm's ...
Jan Černý's user avatar
  • 1,205
0 votes
0 answers
670 views

Delete all files in directories tomcat_*/temp on each application restart

We do have an operation script to stop, restart and start tomcat services. I am asked to make changes in the operation script so when starting tomcat with operation_script.sh, All files in directories ...
codehunter-py's user avatar
12 votes
2 answers
3k views

What does `exec 6>&1` or similar do?

I'm migrating some software from Unix to Linux. I have the following script; it is a trigger of a file transfer. What do the exec commands do? Will they work also on Linux? #!/bin/bash flog=/mypath/...
CarLaTeX's user avatar
  • 329
1 vote
0 answers
1k views

How is i3 window manager started by startx in Ubuntu (so that I can configure what display it appears on)?

I want to set up i3 automatically start on a specific one of my three screens (all connected to one Nvidia card). This has proved more difficult than expected. My first choice was to just set that ...
Stonecraft's user avatar
4 votes
1 answer
496 views

How to increment COUNTER in -exec script?

Context: zsh Catalina MacOS: The executable script BatesStamp engages imagemagick to stamp a number to a jpg file: # BatesStamp: OVERWRITES and stamps ONE file with COUNTER (upper left corner) # ...
gatorback's user avatar
  • 1,214
0 votes
2 answers
187 views

exec vscode not redirecting output to /dev/null

I have the following bash script: exec '/mnt/c/Users/WindowsUserName/AppData/Local/Programs/Microsoft VS Code/Code.exe' $@ &>/dev/null & When I run the script I get ➜ ~ ./code foo.js ➜ ~ ...
Kevin Koehler's user avatar
2 votes
1 answer
321 views

How does exec > work in AWS EC2 user data?

I was writing a Terraform module for AWS EC2 that involved executing a bash in the user data section. While I was developing I had an issue in the script I wrote but neither AWS nor Terraform provided ...
Ahmed Khaled's user avatar
0 votes
2 answers
6k views

exec command not found error in Linux

below commands are giving output and exiting the terminal exec sleep 60 exec pwd below commands throws error. please advise on the exec behaviour $ exec test1.sh -bash: exec: test1.sh: not found $ ...
Veera V's user avatar
  • 33
0 votes
3 answers
343 views

How to pass grep result to a varible so i can use it with exec tar command?

I am trying to compress all folder in dir based on some regex so I used grep to filter out the output now i need to use tar and folder name. For example I want to .tar.gz each top level directory to ...
DevWL's user avatar
  • 141
0 votes
1 answer
312 views

php exec/shell_exec behavior CLI vs CGI

I am trying to use php to run some system commands and am getting a behaviour that I don't fully understand. If the php script is run from the command line I get the results I expect. But running it ...
Gavin Murphy's user avatar
0 votes
0 answers
196 views

Exec Not Updating Values from Certain Bash Functions and Variables When Prepending Script Output

I am logging messages in Bash where I add some useful information to the log message to help provide context. However, in the final output most of my variables and functions appear to only use their ...
Exper1mental's user avatar
-2 votes
1 answer
163 views

Output of this command Linux [closed]

Please do anyone has an idea about the output of this command , I have googled a lot about it but I can't find anything useful find . -type f -exec grep -H PATH {} \; Thanks in advance
askermad789's user avatar
0 votes
0 answers
72 views

OpenBSD 6.9 - ENOMEM error on execve (execvp)

I've compiled a program on OpenBSD 6.9 and when I execute the program, I get an enomem error related specifically to execvp which the man pages say is a font-end for execve. The execve man page ...
brokaryote's user avatar
1 vote
1 answer
267 views

process hangs after redirecting stderr using exec

I want to redirect stdout and stderr to 2 pipes one for each to create the pipes I used: mkfifo -m 0666 /var/run/log_stdout.pipe mkfifo -m 0666 /var/run/log_stderr.pipe and it works fine, but ...
yunger's user avatar
  • 11
0 votes
1 answer
279 views

ip netns exec cannot start ONLY mate-terminal and gnome-terminal?

I am using the newns script from here: https://superuser.com/questions/983727/route-only-specific-traffic-through-vpn ... except on this system: $ mate-about -v MATE Desktop Environment 1.24.0 $ cat /...
sdaau's user avatar
  • 6,668
7 votes
2 answers
3k views

Why does exec print its output after the program exits?

I'm writing a program to pipe one command to another. Inputs will be from the command line: $ ./a.out ls '|' wc c2 PID 6804 c1 PID 6803 PARENT PID 6802 $ 2 2 17 Why does the output ...
Paulson Paul's user avatar
0 votes
2 answers
64 views

How to delete ALL directories but NOT files from another location in execv? [closed]

Let's say I'm at the home directory and I have a directory called 'Apple' that has 2 directories (let's say I don't know their names) with contents in them and several files. I open my terminal in ...
Banana's user avatar
  • 3
0 votes
1 answer
792 views

Why is 'ls' being created by execve() call and not fork()

From my understanding whenever you type a command such as 'ls' in your shell, the parent process which is my shell duplicates itself using fork() system call and then uses the exec() system call to ...
Le Ray's user avatar
  • 103
2 votes
1 answer
315 views

How can I redirect all output of a script to a file and replace passwords?

I'm running a ksh script on AIX 7.2. In debug mode I want to redirect all the script does to a brkpt-file. The script also makes logins to another application and therefore uses a password (let's say &...
rudi's user avatar
  • 23

1
2 3 4 5 6