0
alias testing="date | tee /home/anupamkhatiwada/fulldate.txt | cut --delimiter=" " --field=1 | tee /home/anupamkhatiwada/shortdate.txt | xargs echo hello"

On typing test in terminal and pressing enter getting

testing: command not found

Inian
  • 80,270
  • 14
  • 142
  • 161
progTurd
  • 21
  • 5

3 Answers3

0

Probably because you have embedded " in your string. Try this instead:

alias testing='date | tee /home/anupamkhatiwada/fulldate.txt | cut --delimiter=" " --field=1 | tee /home/anupamkhatiwada/shortdate.txt | xargs echo hello'
PaulProgrammer
  • 16,175
  • 4
  • 39
  • 56
0

When I run that command I get this error message:

-bash: alias: ` --field': invalid alias name

And as PaulProgrammer pointed, seems to be due to the delimiter character used in your cut command, the double quotes ", which conflicts with the ones used to define the alias. Hence, another workaround would be:

alias testing="date | tee /home/anupamkhatiwada/fulldate.txt | cut --delimiter=' ' --field=1 | tee /home/anupamkhatiwada/shortdate.txt | xargs echo hello"
mtnezm
  • 1,009
  • 1
  • 7
  • 19
  • Tried doing that as well along with PaulProgrammer's suggestion both are returning command not found. Its in a file called .bash_aliases in home. – progTurd Jun 09 '20 at 17:26
  • Are you sourcing your `.bash_aliases` file after you make changes on it? Run `source ~/.bash_aliases` and try again. – mtnezm Jun 09 '20 at 18:35
  • This worked like a charm! Thank you so much! I'm doing a udemy course. The instructor didn't mention anything about source. – progTurd Jun 10 '20 at 15:17
0

Define a function instead of an alias, then you don't have to worry about quoting conflicts.

testing() {
    date | tee /home/anupamkhatiwada/fulldate.txt | cut --delimiter=" " --field=1 | 
        tee /home/anupamkhatiwada/shortdate.txt | xargs echo hello
}

Functions have the added benefit that they can take parameters, which can be inserted in the middle of the commands. See Make a Bash alias that takes a parameter?

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Thank you Barmar. I'm doing a udemy course on linux. Haven't reached functions yet but the solution provided by hads0m in comments in the answer below worked. I hadn't declared the source. Actually I didn't know about the source command. – progTurd Jun 10 '20 at 15:20