Help with bash escaping while using screen command


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Help with bash escaping while using screen command
# 1  
Old 01-31-2019
Help with bash escaping while using screen command

Hello, everyone. I'm currently trying to write a command system for a Minecraft server using screen.
Here are the scripts I'm currently using.

0.sh
Code:
#!/bin/bash
screen -S Test114 -dm java -Xmx4G -jar server.jar nogui

1.sh
Code:
#!/bin/bash
args="$@"
args2="${args@Q}"
#args3=`printf '%q\n' "$args"`
echo "args:" $args
echo "args2:" $args2
#echo "args3:" $args3
#printf "$args3"
screen -S Test114 -p 0 -X stuff "$args \r"

The problem is that when attempting to send commands with backslashes in them, the screen command ends up trying to interpret the backslashes.
For example, when I type ./1.sh say \\\\, it'll turn into say \\.
However, screen then further tries to interpret the backslashes. This results in say \.
Is there any way I could write this to get the results I desire? (Also, sorry for the formatting. I tried my best)
# 2  
Old 01-31-2019
Welcome to the forum.


Quoting usually helps. Try
Code:
./1.sh "say \\\\"

or
Code:
./1.sh 'say \\\\'

. Make sure you don't use non-ASCII locale quotes as sometimes introduced by non-*nix editors. On top, using quotes within the script is best practice.
This User Gave Thanks to RudiC For This Post:
# 3  
Old 01-31-2019
Thank you so so much! This fixed everything!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash Vs. Bourne REGEX: metacharacters escaping

I am currently reading a very old reference from O'Reilly: Sed and Awk 2nd Edition reprinted in 2000. So far, it's a solid read and still very relevant. I'd highly recommend this to anyone. The only problem I have with this book is that I had to resort to bourne shell to get my examples to work... (3 Replies)
Discussion started by: ConcealedKnight
3 Replies

2. Shell Programming and Scripting

Wanted: Help with escaping bash command line arguments

Please forgive me if this is the wrong forum. I want to execute some one liners with the groovy programming language and I'm having trouble escaping the special characters to accommodate bash. Here is one of the lines that is giving me trouble: groovy -e "(new... (1 Reply)
Discussion started by: siegfried
1 Replies

3. Shell Programming and Scripting

escaping metacharacters in paths for a shell command

I have a file which contains a list of paths separated by a new line character. e.g /some/path/to/a/file.png /some/path to/another/file.jpeg /some path/to yet/another/file Notice that these paths may contain metacharacters, the spaces for example are also not escaped. If I wanted... (5 Replies)
Discussion started by: cue
5 Replies

4. Red Hat

command line tool to disable screen lock and/or screen saver

Hi, I have a simple question : how to disable screen lock and/or sreen saver with command line with RHEL5.4 ? (1 Reply)
Discussion started by: albator1932
1 Replies

5. Shell Programming and Scripting

Bash: capturing *Anything* which showed on screen

Hi, I have a simple question about I/O redirection. the question is: "How can I redirect all characters from a Bash screen to a file?" Let me describe a little more: I know about I/O Redirection in Bash. and also about stdin/stdout/stderr. something like: # ls 2>&1 1>ls.out But!... (11 Replies)
Discussion started by: siavash
11 Replies

6. Shell Programming and Scripting

Clear Screen Command for BASH shell

I am unable to use clear or cls command on bash shell. I have recently installed Cygwin and am using that for practicing unix commands. I see that I can use Ctrl + L to clear the screen. I created an alias in my .bashrc to do the same as alias cls='^L' This is how i defined other aliases ... (4 Replies)
Discussion started by: erora
4 Replies

7. Shell Programming and Scripting

Escaping '*' in Bash

I have the following situation ============ export DirectoryName=/tmp/xyz if ; then some_new_env=$DirectoryName"/*" ======================= I tried all the ways of escaping the '*', but still the shell seems to expand the '*' character. I want some_new_env to contain "/tmp/xyz/*" ... (7 Replies)
Discussion started by: rkshukla14
7 Replies

8. Shell Programming and Scripting

find: problems escaping printf-command string

Hi Folks! Can you help me with this find -printf command. I seem to be unable to execute the printf-command from my shell script. I'm confused: :confused: My shell script snippet looks like this: #!/bin/sh .. COMMAND="find ./* -printf '%p %m %s %u %g \n'" echo "Command: ${COMMAND}"... (1 Reply)
Discussion started by: grahamb
1 Replies

9. Shell Programming and Scripting

bash script help: escaping the '*'

hi there. i have a simple bash script that reads a word from a text file one at a time, and if a '*' character is encountered, it prints a message. however it doesn't work as i expected. :o what am i doing wrong here? thanks very much for the help :) for word in `cat $DOC` do if... (18 Replies)
Discussion started by: mark_nsx
18 Replies

10. UNIX for Dummies Questions & Answers

ctrl-c: not escaping command

using ksh on HP 11.11. I'm new to HP, so maybe it's something I need to turn on in HP, but I figured it's probably in ksh. If I run "grep aaa" (or any command) Whenever I try to Ctrl-C it does not work. I'm not saying it did work before, as I'm new to the environment. Do I need to set a... (3 Replies)
Discussion started by: dangral
3 Replies
Login or Register to Ask a Question