0

So I'm trying to compose a string using script shell

#!/bin/sh
blNumber=1111619832
echo '*'$blNumber+='*.xlsx'

I expect the output to be: *1111619832*.xlsx but as a result I get: *+=*.xlsx

Btw I tried to figure out why so I tried this code

#!/bin/sh
blNumber=1111619832
output="*${blNumber}"

and whenever I add something after *${blNumber} it get concatenated at the begging of the string

user1934428
  • 19,864
  • 7
  • 42
  • 87
Hamza LAHLOU
  • 69
  • 1
  • 6
  • 1
    Watch your shebang! [`sh` isn't necessarily `bash`.](https://stackoverflow.com/a/5725402/4518341) – wjandrea Jul 01 '21 at 16:06
  • @HamaLAHLOU : Removed bash tag, because the question is not bash-related. – user1934428 Jul 02 '21 at 07:34
  • @HamaLAHLOU : Just use `b1Numer="$b1Number.xlsx"`, or more general, `b1Numer="${b1Number}.xlsx"` – user1934428 Jul 02 '21 at 07:35
  • @HamzaLAHOU : You can - with few exceptions, which don't apply here - not modify a variable inside another statement. You have to first write a statement which changes the variable, and then you can use it in i.e. an `echo`. – user1934428 Jul 02 '21 at 07:37

1 Answers1

1

Why are you using += in the first place?

$ echo '*'$blNumber'*.xlsx'
*1111619832*.xlsx

Or put it inside double-quotes. It's best practice to quote all variables anyway.

$ echo "*$blNumber*.xlsx"
*1111619832*.xlsx
wjandrea
  • 28,235
  • 9
  • 60
  • 81