Self-Motivated Wu
Self-Motivated Wu

Reputation: 407

How to use background execute in bashrc with alias?

I want to replace complex commands with simple characters and execute in background, so I can shut down the terminal.

The command is nWave -ssf test.fsdb(fsdb is a wavefile). In bashrc, I write alias nwave='nWave -ssf'.

If I want the command to be executed in background, I use nWave -ssf test.fsdb &. How to realize this command when using alias in bashrc file.

Upvotes: 0

Views: 378

Answers (1)

dash-o
dash-o

Reputation: 14452

If you plan to close the terminal, you probably want to wrap the command in nohup. However, using 'nohup alias ...' will not work - as nohup only accept regular command. You can embed the nohup into the alias explicitly.

# In bashrc
alias bgnwave 'nohup nWave -ssf'

# At the terminal
bgnware test.fsdb &

As an alternative to bash alias, consider using bash function

function bgwnwave {
    nohup nWave -ssf "$@" &
}

Upvotes: 1

Related Questions