2

I found that it happens because it splits entered arguments. But I am creating a program that encrypts string and it encrypted "test" as |m{|. But when I switch to decryption mode that thing happens. Any solution ?

wjandrea
  • 14,109
  • 4
  • 48
  • 98
Stel Team
  • 43
  • 4

1 Answers1

5

The > comes from bash's $PS2 variable. man bash says:

PS2    The value of this parameter is expanded as with PS1 and used as the secondary prompt string.  The default is ``> ''.

I often see > when I have an unmatched quote (") or apostrophe ('), or some other input that bash views as incomplete.

waltinator
  • 35,099
  • 19
  • 57
  • 93
  • Is there any way to input "|m{|" (without quotes) into terminal ? – Stel Team Jan 16 '19 at 16:10
  • 1
    @StelTeam I believe terminal is waiting for you to enter `}`. What's wrong if it is enter within double quotes? I think it is just a filename. Isn't it? – Kulfy Jan 16 '19 at 16:44
  • @Kulfy The string |m{| is the encrypted version of "test". so the program must take |m{| as an argument in order to decrypt it as "test" – Stel Team Jan 16 '19 at 16:46
  • 3
    ... if you enter `"|m{|"` `'|m{|'` in the shell as an argument to your program, your program will not see the quotes (they will simply prevent the shell from trying to interpret the sequence) – steeldriver Jan 16 '19 at 16:51
  • @StelTeam Without quotes `|` will be treated as pipe symbol and `{` as start of compound command, therefore the shell will treat it as part of its syntax and consider the line you entered incomplete. That's what `>` signifies. – Sergiy Kolodyazhnyy Jan 16 '19 at 21:07
  • @SergiyKolodyazhnyy Okay. So I cant enter that string to terminal? Is there any way? – Stel Team Jan 16 '19 at 21:09
  • @StelTeam You could enter hex value for the characters , such as `$'\7b'` for `{`, but otherwise - no. Quoting is a necessity in this case. If you are OK with using `read` command to prompt user for string, such as `read -p "Enter encrypted string:" var_to_store` and then use `$var_to_store` - then it can work. Shell won't treat characters specially with `read`. But when you type it as `./mycommand.sh arg1` , then arg1 has to follow shell rules – Sergiy Kolodyazhnyy Jan 16 '19 at 21:13
  • @SergiyKolodyazhnyy if you can post it as answer I can access it. Thank you! – Stel Team Jan 16 '19 at 21:14