Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

two arguments problem with quotes #82

Closed
jaker-dotcom opened this issue Sep 14, 2021 · 2 comments
Closed

two arguments problem with quotes #82

jaker-dotcom opened this issue Sep 14, 2021 · 2 comments

Comments

@jaker-dotcom
Copy link

jaker-dotcom commented Sep 14, 2021

Hello there!

I ran into trouble but fixed the problem myself. Am posting anyway for gaining a better understanding. I am trying to run a couple of commands with entr and expand one of the commands with parameter expansion. I created a function in .profile

entrtaskprojfunction () {
	ls ~/.task/pending.data | entr -c task project:$1 rc.gc=0 2>~/.task/taskerrormessages.txt | grep  "\."
}
alias entrtaskproj='entrtaskprojfunction'

Now I want to be able to specify the project I want to work on and have it display the tasks within that project and have it reload upon changes to the task database.

The problem: I first didn't get it to clear the screen. I think was because of piping into grep not being part of the command entr runs. I know that you can run two commands like in #7 but that doesn't work due to the double-quotes which I need for both the shell parameter expansion. Now I put sh -c in front and add double-quotes around both commands. I thus needed to change the quotes around the expression for grep to single-quotes. This did the trick. But suppose I want to have entr run commands which require double-quotes themselves (e.g. displaying with echo what project the tasks belong to). Is there a shell inbuilt way of managing such cases? Or would it be necessary to create a script for this?

Here my code which solved the problem:

entrtaskprojfunction () {
	ls ~/.task/pending.data | entr -c sh -c "task proj:$1 rc.gc=0 2>~/.task/taskerrormessages.txt | grep  '\.'"
}

If nobody feels like answering to this just delete the issue, I understand that this is not really entr-related but due to me being rather new to the shell.

Thanks!
Jaker

@eradman
Copy link
Owner

eradman commented Sep 17, 2021

Your question is fair because entr a command-line utility.

I suppose the most comprehensive solution is to wrap complex functionality in another script

entrtaskprojfunction () {
    ls ~/.task/pending.data | entr -c "./run-task.sh $1"
}

There is also a -s flag which is intended as a shorthand for sh -c

The first thing you can try is mixing double-and single quotes

entr -c -s "echo 'one   two'" 

You should also be able to escape double quotes

entr -c -s "echo \"one   two\"" 

Let me know if this helps!

@jaker-dotcom
Copy link
Author

I feel like knowing that escaping quotes is possible will come handy in the future. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants