M
M
muhasa2020-01-22 13:26:06
linux
muhasa, 2020-01-22 13:26:06

How to remove a space in a parameter in bash?

People, I can't figure out where the mistake is

first=$(echo $1 | xargs)
alias trunc_spv='echo /var/log/supervisor/$first'

This code does not cut spaces, but if you write instead, spaces will be cut. Specifically, the task is such. It is necessary to make an alias that will execute the command to clean up a file in a specific directory. The directory is static, only the file in that directory is dynamic. But the file comes with a space in front of $1, so the space needs to be cut. How?.. Thank you!
first=$(echo $1 | xargs)
first=$(echo ' p ' | xargs)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Karpion, 2020-01-22
@muhasa

first=$(echo "$1" | xargs)- put the shell variable in quotation marks.

K
ky0, 2020-01-22
@ky0

man tr
https://linux.die.net/man/1/tr

M
muhasa, 2020-01-22
@muhasa

In short, everything was simple - aliases do not allow parameters to be used (((

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question