Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

My shell-fu isn't the greatest. I thought I could be clever and do

    >alias rip="curl -G -H 'Accept: text/plain' \
    --url https://dontbeevil.rip/search --data-urlencode q="

    >rip hello
    {"message": "Missing required request parameters: [q]"}
    curl: (6) Could not resolve host: hello


Turn it into a function:

    rip() {
        curl -G -H 'Accept: text/plain' \
        --url https://dontbeevil.rip/search --data-urlencode "q=$@"
    }
Now `rip hello` works.


This only works with 1-word arguments. You can change $@ to $* to fix that.

(I'm acting all wise, but I learned that today as well :) )


Switch to Zsh, where there'll be no difference!


You could also put a shell script on your `PATH` instead of creating an alias:

  #! /bin/sh
  query_string="q=$@"
  curl --get \
    --header 'Accept: text/plain' \
    --url https://dontbeevil.rip/search \
    --data-urlencode "${query_string}"


I'd do it almost the same but without the variable. Note: the long shebang is for using on Termux, PC users should change it to something like #!/use/bin/env sh.

   #!/data/data/com.termux/files/use/bin/env sh
  curl -G -H "Accept: text/plain" \
  --url "https://dontbeevil.rip/search" \
  --data-urlenconde "q=$*"


Didn't know about "$*", thanks!

Edit: typo in your version: "urlenconde"


Also every instance of ‘usr’ has been autocorrected to ‘use’.

Autocorrect does make me laugh some days :D


That's what I get for phone posting. Thanks for pointing it out you two!


  function rip() {
    printf ">>"
    read query
    curl -G -H 'Accept: text/plain' --url 
  https://dontbeevil.rip/search --data-urlencode q="$query"
  }
:)




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: