Question regarding curl command

Hi all, :wave:

I just stumbled over an interesting article “Check Tiny URLs” on Tiny-URLs prüfen - GNU/Linux.ch (in German) .

Shortened URLs are especially popular if you have little space for transmission, e.g. in microblogging services.
There you will find short URLs created with a URL shortener, such as tinyurl.com or t1p.de.
These services create a mapping of the shortened URL to the actual URL.

The problem with this is that you don’t see where the shortened URL actually shows. If you want to be sure where the short URL leads,
you can use a simple command in the terminal. Take this shortened URL as an example: GNU/Linux.ch. Don’t worry, you can click on it; she points to gnulinux.ch.

To check the shortened URL, you copy it and open a terminal. Then you call the following order:

curl -l tinyurl.com/4k43b55m

(translation via “TranslateLocally for Firefox” add-on)

That´s fine so far.
Yet the screenshot on the page shows a coloured output on the terminal whereas my output remains monochrome.

So I thought “why not piping it to bat”?
That I did with the following command:

firejail curl -l tinyurl.com/4k43b55m | bat

and indeed I got coloured output :wink: :

As you can see in the screenshot there´s the additional download-like info


% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   326    0   326    0     0    686      0 --:--:-- --:--:-- --:--:--   687

I also get that when using cat instead of bat
… but NOT if I use curl-command without piping it to bat or cat. :thinking:

Hmm, I wonder what´s behind that logic.
Can anybody help me solve the riddle :question:

Many thanks in advance and many greetings.
Rosika :slightly_smiling_face:

2 Likes

I get monochrome with curl even when piping through cat.

I don’t have bat, but here is from their man page.

bat (1)

NAME

bat - manual page for bat

DESCRIPTION

bat - a cat(1) clone with syntax highlighting and Git integration.

It says, “with syntax highlighting”. Maybe cat is an alias for bat on your machine?

2 Likes

@pdecker:

Hi and thanks for your reply, :wave:

Yes, this way I also get monochrome. It´s only when piping through bat that I get the colored output.
Well, that´s fine then.

What I´m really interested in however is why I get the additional output

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   326    0   326    0     0    686      0 --:--:-- --:--:-- --:--:--   687

only when piping the result through either cat or bat:thinking:

Without the piping curl has just this output:

firejail curl -l tinyurl.com/4k43b55m
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="refresh" content="0;url='https://gnulinux.ch/'" />

        <title>Redirecting to https://gnulinux.ch/</title>
    </head>
    <body>
        Redirecting to <a href="https://gnulinux.ch/">https://gnulinux.ch/</a>.
    </body>
</html>⏎

Many greetings
Rosika :slightly_smiling_face:

1 Like

Oops, I kind of missed your question on the progress display when piping I guess.

I see the same progress when piping to anything, but there is a “-s” parameter for silent to remove that.

Not sure why it is shown, but I’ve noticed that type of behavior before with wget too I think.

$ curl -l -s tinyurl.com/4k43b55m | more
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="refresh" content="0;url='https://gnulinux.ch/'" />

        <title>Redirecting to https://gnulinux.ch/</title>
    </head>
    <body>
        Redirecting to <a href="https://gnulinux.ch/">https://gnulinux.ch/</a>.
    </body>
</html>

The color here was not shown on my local computer. It must be added by formatting it on the forum as code.

1 Like

Thanks @pdecker for your new answer, :wave:

I tried it and it woks, like you said. Thanks so much for bringing the “-s” parameter to my attention. Hadn´t known it before. :blush:

I also looked it up and man-pages say:

-s, --silent
Silent or quiet mode. Don’t show progress meter or error messages. Makes Curl
mute. It will still output the data you ask for, potentially even to the ter‐
minal/stdout unless you redirect it.

O.K., I´ve learnt something new again.

By default it seems (I´m by no means sure of that) that curl implements the “-s” option.
When piping the result to another command however the progress bar is shown.
If this behaviour is not wanted the “-s” option has to be set manually then (like you pointed out).

Thanks a lot, @pdecker, for your help. :kissing_closed_eyes:

Many greetings from Rosika :slightly_smiling_face: