Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

new line inside an alias command without newline character

I want to setup an alias that would show useful git commands to make it easier to find what I’m looking for, and echoing each to a new line

alias git_help='echo "Delete local branch: git branch -d <branch_name>" \n; echo "Delete remote branch: git push origin --delete <branch_name>" \n'

but each time I run it, while the output does break into a newline, the ‘n’ character is still there:

Delete local branch: git branch -d <branch_name> n
Delete remote branch: git push origin --delete <branch_name> n

Is there a way to do this without printing the ‘n’ character at the end of each line?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

echo already adds a newline, so just remove the \n entirely.

[user@host]$ alias git_help='echo "Delete local branch: git branch -d <branch_name>" ; echo "Delete remote branch: git push origin --delete <branch_name>"'
[user@host]$ git_help
Delete local branch: git branch -d <branch_name>
Delete remote branch: git push origin --delete <branch_name>
[user@host]$

Using a function over an alias may make this easier to understand.

git_help() {
  echo "Delete local branch: git branch -d <branch_name>"
  echo "Delete remote branch: git push origin --delete <branch_name>"
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading