Follow

wc -l ${2} || exit 1

Why is the return value 0? :angry_pepe:

· · Web · 2 · 1 · 0
@matrix What's the point of '|| exit 1'? wc should return 1 after an error.
@matrix Huh.
What are you trying to achieve anyway?

@grips "V souboru zadaném druhým argumentem spočítá počet řádků a předá číslo na standardní výstup a úspěšně skončí (pokud soubor existuje). Pokud soubor zadaný druhým řádkem neexistuje, musí skript skončit neúspěšně (tj. s nenulovým návratovým kódem, použijte např. exit 1) a současně musí předat chybové hlášení (libovolné, neprázdné) na standardní chybový výstup"

@matrix hmmm, try this:

#!/bin/bash
wc -l "$2" | cut -d " " -f 1 && exit 0
echo "oh boy you goofed up :^)" >&2
exit 1
@matrix alternatively (line 2 replacement):
cat "$2" | wc -l && exit 0

@grips Is Aisa retarded or am I retarded? Still says return value 0.

@matrix Ah right.
Trying to think about something not too verbose but it's hard... maybe in a few minutes.

@matrix Wait a second⦠second argument? Whatâs the first for then?

@matrix Aight. Disregarding that part:

#!/bin/bash out=$(wc -l "$2") if [ $? == 0 ]; then echo $out | cut -d " " -f 1 exit 0 else echo "oh boy you goofed up :^)" >&2 exit 1 fi

fookin hell

@matrix Anytime. :^)
When's the deadline for everything - before the exam like it used to be? We could meet up and take a look at some other lab levels you're struggling with.

@grips
Thanks, I'm probably fine. Just one script and Vi remaining.

Sign in to participate in the conversation
Game Liberty Mastodon

Mainly gaming/nerd instance for people who value free speech. Everyone is welcome.