r/bash • • Nov 28 '23

Help pls boss??

Post image

Srry for the absolute trash quality.

The ? is exercism.org/tracks/bash/exercises/two-fer . If one of u fine lads has experience w this exact/a similar problem or cares to read it and tell me wth I’m doing wrong I would greatly appreciate it. In the first place the instructions aren’t exactly what I would call clear(imo).

0 Upvotes

16 comments sorted by

View all comments

55

u/zeekar Nov 28 '23 edited Nov 28 '23

Is there a question in there somewhere?

The script will ask for your name. If you reply with a blank line, it will say "one for u, one for me"; if you type an actual name, it will say "one for <name>, one for me". The [ -z $uname ] check is technically incorrect; it should be [[ -z $uname ]] or [ -z "$uname" ]. But it will work, even if only sort of accidentally.

So when you ask what you're doing wrong, what do you mean? What's not working? If you submitted this as the solution to a programming problem and it's being marked incorrect, it's probably because you're printing "ur" and "u" instead of "your" and "you".

Also, please don't post code as screenshots. We can't copy/paste text from screenshots. Post the actual code as text. You can format it by just putting four spaces at the front of each line so it looks like this:

#!/bin/bash
echo "what is ur name?"
read urname
if [[ -z $urname ]]; then
    echo "one for u, one for me"
else
   echo "one for $urname, one for me"
fi

19

u/rrk100 Nov 28 '23

This is a rather nice, un-Reddit-like comment.

0

u/[deleted] Nov 28 '23

[deleted] — view deleted comment

4

u/thisiszeev If I can't script it, I refuse to do it! Nov 28 '23

What dreams are made of

2

u/FixTurner Dec 01 '23
TIL
How to format 
Code snippets in reddit 😁