Insert a character without typing it - Command Line *nix
- Vous devez vous identifier ou créer un compte pour écrire des commentaires
Hi, English it's not my mother language, expect errors.
I have a laptop with a a broken keyboard, i have a US keyboard that i attach to the laptop to use it, but i don't use it with the US layout (i use the Spanish layout).
Anyway, sometimes i need to redirect stdin and stdout but i can't use < > (the redirections character), if i use Spanish layout in a US keyboard. Because i'm in a very limited shell with no X support, only kmaps and busybox sh.
My question is: Is there any way to print a character and use it i as if it was introduced with the keyboard?
I have tried doing this:
$ cat $(echo -e '\076') test.file
cat: >: No such file or directory
cat: test: No such file or directory
Thank you.
> My question is: Is there any way to print a character and use it i as if
> it was introduced with the keyboard?
$ sudo apt install xdotool
And map "xdotool key <" to something. Executing that command will output
"<" as if you had typed it from the keyboard.
As i mention before it's a minimal system, no X, busybox sh and basically no internet acces.
Thank you, but that would not work for me. I already workaround this doing the following:
$ echo -e '\076' | less
then i press the 's' keys to save a log, which is the >. Then i edit the file with vi.
cat > test
I change the permissions
$ chmod +x my_file
$ ./my_file
I don't want to do that every time i need the characters < >
That's why i want to know if there is a method to put them in the prompt/terminal without saving them in a script.
I even try this:
$ exec cat $(echo -e '\076') my_file
exec it's beyond my knowledge, so i'm not sure of what i'm actually doing.
Maybe look at remapping some other key combination to perform the function of the missing keys. You can do it without any X stuff. Trisquel has the kbd package with programs like dumpkeys, showkey, and loadkeys. I encourage you to examine these.
Ok, i will study those programs, thank you.
So, there are no way i can do it directly in the shell?
Yes! I did it!
This does the job:
$ eval cat $(echo -e '\076') test_file
I remember reading about eval just a few days ago, and the role it play in a security bug in bash, because they where using eval a lot in the code and that ended up with file names or strings executed as code. Just exactly what i want.
EDIT:
Now i have another issue in bash and busybox sh with the here-document << EOF
And i try to use several variants of the line.
# eval cat $(printf '\074\074') EOF
bash: warning: here-document at line 346 delimited by end-of-file (wanted `EOF')
# eval cat $(printf '\074\074'EOF)
bash: warning: here-document at line 347 delimited by end-of-file (wanted `EOF')
# eval cat $(printf '\074\074EOF')
bash: warning: here-document at line 348 delimited by end-of-file (wanted `EOF')
# eval cat $(printf "\074\074EOF")
bash: warning: here-document at line 349 delimited by end-of-file (wanted `EOF')
# eval cat $(printf '\074\074')$(echo -n EOF)
bash: warning: here-document at line 350 delimited by end-of-file (wanted `EOF')
# eval cat $(printf '\074\074')$(printf EOF)
bash: warning: here-document at line 351 delimited by end-of-file (wanted `EOF')
The following was the closest i was to getting it working because it doesn't show me the warning as i press enter.
# eval cat $(printf '\074\074')\
> EOF
bash: warning: here-document at line 352 delimited by end-of-file (wanted `EOF')
I try with SH of busybox, but shows nothing.
# busybox sh -c eval cat $(printf '\074\074')EOF
#
# i=EOF ; eval cat $(printf '\074\074')$i
bash: warning: here-document at line 407 delimited by end-of-file (wanted `EOF')
# eval cat $(printf '\074\074'-EOF)
bash: warning: here-document at line 421 delimited by end-of-file (wanted `EOF')
bash: syntax error near unexpected token `newline'
The following doesn't work:
# eval cat $(printf '\074\074') \
> u
bash: warning: here-document at line 441 delimited by end-of-file (wanted `u')
And this is the same as the above but not eval or printf involved. The following works as expected.
# cat << \
> u
> test
> u
test
(Second part of the post, it's seems that the forum executes the code inside the post.)
It's seems like bash didn't like to have any character before and after the EOF, that why it shows me the warning.
I can't use this method to do a here-document and it's seems like it can't be done with bash because the way it's designed, and busybox sh simply can't do it.
But i still can use it in a script.
# ./test_file
# this
# is a
# test ,
# cat test_file
#!/bin/sh
# sh -c cat <
- Vous devez vous identifier ou créer un compte pour écrire des commentaires