2

I have a professor who stores homework assignments in many files spread across different sub-directories in a lecture folder with the header "TODO:" I'd like to output all these todo's to a single text file in nano instead of navigating from one assignment file to another.

I tried to make an alias for this command, since I use it so much, but whenever I try to execute it, the cursor just blinks and nothing happens.

alias todo='cd /home/csc103/Desktop/shared/csc103-lectures && grep -Rw "TODO:" --after-context=6  --include="*.cpp" . > todo.txt && nano todo.txt'

What am I doing wrong here?


Edit

by "Nothing Happens" I mean that the cursor keeps blinking and the next prompt doesn't come up. As in the left terminal pane in the image below. No Additional Prompt

However, when I force-quit the process with ctrl-C I do end up in the directory I wanted the todo command alias to take me to. And there is a todo.txt file in there. Csc103-lectures is the right directory

Also, if it's of any relevance I'm issuing these commands on an Arch Linux install in VirtualBox.

  • 3
    My guess is your grep didn't find anything, so it returned a nonzero exit status which means the last && skipped your nano invocation. – jw013 Oct 8 '16 at 5:16
  • 2
    @user14903: What do you mean by “nothing happens”?  Do you mean that nothing happens?  Or that nano starts but the screen is blank?  Or that you get your shell prompt back?  What directory are you in after whatever happens, happens?  Is a todo.txt fle created?  What’s in it? Are you saying that this exact same command works when you type it, but not when you run it via an alias?  Please do not respond in comments; edit your question to make it clearer and more complete. – G-Man Says 'Reinstate Monica' Oct 8 '16 at 8:15
0

I figured it out, thanks for the pointers guys. The problem here was that grep was recursively searching for "TODO:" in the todo.txt file and then writing those results back to the todo.txt file. When I opened todo.txt it was filled with the same text looped over and over again. Evidently, I should have used the --exclude="todo.txt" option in grep. After adding that, it works perfectly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.