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).
bashisn't the right language to use if you need to manipulate a string like this.${#var}. 2) To get the nth character of a string, you can use:${var:n:1}wherencan be a variable. 3) To loop over the characters, you can use C-styleforloop:for ((i=0; i<${#var}; i++)); do echo ${var:i:1}; done. But as @chepner mentioned,bashis not the right tool.