0

I hope my question won't offend you, but I have a problem working with characters. I'm using an Oracle VM environment, where I've installed a Linux image. I have to create a script which will take 2 arguments: a word and a key. I have to encrypt the given word using the key. The problem is that I have to change the word letter by letter and I don't really know how to do that. My script's code:

#!/bin/bash
INPUT=$1
KEY=$2
while [ $[#KEY] -lt $[#INPUT] ]
do
  KEY=$KEY$KEY
done
nr=$[#INPUT]
for i in {0..nr}
do
  echo "$(INPUT[i])"
done

I don't have any experience in Linux commands and, especially, in characters manipulation (I used to use them quite often in C, but it seems that Linux has different rules for characters).

Jens
  • 69,818
  • 15
  • 125
  • 179
  • This has nothing to do with Linux. If you're writing your program in bash, then you need to learn how bash works. – melpomene Dec 30 '17 at 15:41
  • 2
    `bash` isn't the right language to use if you need to manipulate a string like this. – chepner Dec 30 '17 at 15:48
  • Some hints: 1) To get length of a variable, use: `${#var}`. 2) To get the nth character of a string, you can use: `${var:n:1}` where `n` can be a variable. 3) To loop over the characters, you can use C-style `for` loop: `for ((i=0; i<${#var}; i++)); do echo ${var:i:1}; done`. But as @chepner mentioned, `bash` is not the right tool. – PesaThe Dec 30 '17 at 16:14
  • what do you suggest me to use,besides bash? – Mada Croitorescu Dec 30 '17 at 17:52

0 Answers0