Bash - Exec (No New Process) - builtin command

> Procedural Languages > Bash Shell and (Unix|Linux) Utilities (XCU)

1 - About

If command is specified, it replaces the shell. No new process is created. The shell terminates.

Advertising

3 - Syntax

exec [-cl] [-a name] [command [arguments]]

where:

  • arguments become the arguments to command.
  • -l the shell places a dash at the beginning of the zeroth arg passed to command. This is what login(1) does.
  • -c option causes command to be executed with an empty environment.
  • -a : the shell passes name as the zeroth argument to the executed command.

4 - Return value

If command cannot be executed for some reason,

If command is not specified, any redirections take effect in the current shell, and the return status is 0. If there is a redirection error, the return status is 1.

Advertising

5 - With Ssh

The Ssh protocol permits to call an exec command.

5.1 - Maven and ANT

An example of calling exec with Maven through Ant.

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-antrun-plugin</artifactId>
	<version>1.7</version>
	<executions>
		<execution>
			<id>scp</id>
			<phase>install</phase>
			<configuration>
				<target>
					<sshexec
							host="${deploy-host}"
							username="${deploy-username}"
							password="${deploy-password}"
							command="/export/myscript.sh"
							trust="yes"
							/>
				</target>
			</configuration>
			<goals>
				<goal>run</goal>
			</goals>
		</execution>
	</executions>
	<dependencies>
		<dependency>
			<groupId>org.apache.ant</groupId>
			<artifactId>ant-jsch</artifactId>
			<version>1.8.2</version>
		</dependency>
	</dependencies>
</plugin>

6 - Documentation / Reference