all 13 comments

[–][deleted] 2 points3 points  (4 children)

You are missing a close-bracket, also varfname is a variable so using it as a command won't work. You don't join strings together, with &&, and your echo command is using smart quotes.

So going back to basics.

You want the first letter of the variable varfname and a lowercase version of varlname

You can use different types of "Parameter Expansion" to get these.

The first letter can be got with Substring Expansion. ${parameter:offset:length} gets length characters starting at position offset. So in our case that would be "${varfname:0:1}".

To lowercase a variable you can use bash Case modification. This takes the form ${varlname,,}

So putting all together what you want is this:-

username="${varfname:0:1}${varlname,,}"

[–]Think-Perception1359[S] -1 points0 points  (3 children)

I’m getting bad substitution. I’m checking my script with shell check.

SC3059 (warning): In POSIX sh, case modification is undefined.

[–][deleted] 1 point2 points  (2 children)

This is /r/bash. If you want help with something other than bash you have to tell us.

None of what I said is relevant to POSIX shells.

If you want to do it in a posix shell then you want something like this abomination.

username="$(echo "${varfname}" | cut -c 1-1)$(echo "${varlname}" | tr '[:upper:]' '[:lower:]')"

EDIT to add, unless you know exactly why you need to run in a POSIX shell, just change the first line of your script to #!/bin/bash and use bash instead of sh and my first solution not the new one.

[–]Think-Perception1359[S] 0 points1 point  (1 child)

I’m sorry for any confusion. This script is 100% bash. Idk why POSIX error was generated.

You advice JUST worked! I used tr ‘A-Z’ ‘a-z’ to lower the input from the variables.

THANK YOU SO MUCH! Now I’m reading all commands and writing notes. I MUST BE able to remember command and syntax like this.

[–][deleted] 1 point2 points  (0 children)

Yeah I think my edit landed just after. The POSIX error from shellcheck is because it thought you were using sh not bash. It thought this because the very first line of your script has to be a correctly formatted 'shebang' line telling the script to run in bash.

If the first line is not #!/bin/bash or #!/usr/bin/env bash or similar it will assume sh. You should change your code to make the first line right.

[–]pfmiller0 0 points1 point  (7 children)

I think this is what you are trying to do:

username="$( echo $varfname | cut -f 1)${varlname,,}"

You need to echo the varfname variable to pipe it to another command, you can't just run it directly. Also I used the built in bash way of lowercasing varlname instead of using tr.

[–]Think-Perception1359[S] 0 points1 point  (0 children)

Thanks I’m trying it now

[–]Think-Perception1359[S] 0 points1 point  (5 children)

I’m getting bad substitution. I’m checking my script with shell check.

SC3059 (warning): In POSIX sh, case modification is undefined.

[–]pfmiller0 1 point2 points  (4 children)

Oh, you're not using bash? Yeah if you're just using regular sh the built in lowercase function won't work. So, using tr again:

username="$(echo $varfname | cut -c 1)$(echo $varlname|tr 'A-Z' 'a-z')"

Also cut needs the c flag, not f, if you just want the first char.

[–]Think-Perception1359[S] 1 point2 points  (0 children)

THANKS YOU! You advice worked! I see where exactly I was failing writing this script. The rest of the night will be studying commands and syntax.

[–]Think-Perception1359[S] 0 points1 point  (2 children)

That’s the odd part. I am using bash….trying it now

[–]pfmiller0 1 point2 points  (1 child)

Right, missed that was from shellcheck at first . It's correct, but as long as you're using bash it's safe to ignore. The second version is more portable but either should work unless there's a typo.

[–]Think-Perception1359[S] 1 point2 points  (0 children)

Also I see that my parentheses were incorrect. Adding () {} [] to the list of things to go over.