LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Blogs > crajor
User Name
Password

Notices


Rate this Entry

Syntax is important!

Posted 10-16-2020 at 10:28 PM by crajor
Updated 10-16-2020 at 10:31 PM by crajor (typo)

This is a story that should help us all see how important syntax is in linux commands. I had recently installed PCLinuxOS2020, and I wanted to set up some aliases in this new install. It had been awhile since I had last done this, so I did a search to get info on how to make these aliases permanent. Not hard to find and got the info I needed to do that.
Per instructions, I created a .bash_aliases file wherein I put my aliases.
Quote:
alias rf=clear
alias rfa= source ~/.bash_aliases
I then appended .bashrc per instructions so the source command would properly be executed
Code:
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
I was excited! I had figured it out (with help)! Only to find out that something was wrong...
the source command was not right - the file was not being seen. First I checked to be sure the file was there - yep, it existed in my home directory. Thought there might be a problem with permissions, but when permissions for .bash_aliases was compared to permissions for .bashrc, both were the same so permissions did not seem to be the issue. I decided to walk away for awhile (frustration) (other things to do).
Returned in evening and boot up made no difference - same problems existed. However, having walked away for awhile allowed me to see something that I didn't think of earlier. Alias has a syntax for commands (which I had completely forgotten). So I tried an edit of the .bash_aliases file:
Quote:
alias rf=clear
alias rfa= "source ~/.bash_aliases"
Unfortunately this did not solve the problem. So I did a simple alias command and was shown that commands were wrapped in single, not double quote marks! Another edit of .bash_aliases;
Quote:
alias rf=clear
alias rfa= 'source ~/.bash_aliases'
Still didn't work! What the ...
AHA! One more time;
Quote:
alias rf=clear
alias rfa='source ~/.bash_aliases'
TaDa! Success!
Now most of you coders out there may LAUGH LAUGH LAUGH at this entry because you have probably seen a situation like this a million times before in your work. I am speaking to the folks like myself that do not deal with this on a daily basis. Syntax is important - improper application of symbols and spaces CAN keep a command from doing the job.
I first set up the commands with no quotes, then the wrong type of quotes, and then an extra space which does not even belong in the command.
So if you are struggling with a command, remember the importance of syntax. If the command is not written correctly, it won't work. DO take the time to make certain your syntax is correct.
Posted in Uncategorized
Views 997 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 05:27 PM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration