enter stomp command using telnet - terminal

I am trying to enter the following command in Mac terminal using telnet, however it does not return anything. Which keyboard combination should I use in order to enter the command?( I used ^D ^V ^M, they did not work )
CONNECT
login: admin
passcode: password

From the STOMP spec:
CONNECT
login: <username>
passcode:<passcode>
^#
The ^# is a null (control-# in ASCII) byte. The entire thing will be
called a Frame in this doc. The frame starts with a command (in this
case CONNECT), followed by a newline, followed by headers in a
: with each header followed by a newline. A blank line
indicates the end of the headers and beginning of the body (the body
is empty in this case), and the null indicates the end of the frame.
To enter the nullbyte ^# on a Mac OSX terminal:
Press control+#
Type control+v and then control+m

I found the answer.
After typing the command, leave 1 line blank and then on the next line enter kntrl+v kntrl+m

Related

Why is there no such file or directory_profile?

I am using Windows and MobaXterm.
I created a .bash_profile file in the ~ directory and the following line
alias sbp="source ~/.bash_profile"
is the only code in that file.
However, when I was trying to do sbp, I got an error.
This works on my Mac and it used to work on my old Windows computer (but that one has some water damage so it broke down). Why does this not work now?
Thanks in advance!
From the way that error message is garbled I'm pretty sure that the .bash_profile file you created has DOS/Windows-style line endings, consisting of a carriage return character followed by a newline character. Unix tools expect unix-style line endings consisting of just a newline; if they see DOS/Windows-style endings, they'll treat the carriage return as part of the content of the line. In this case, bash will treat the carriage return as part of the alias definition, and therefore part of the filename to filename to source. Try running alias sbp | cat -vt to print the alias with invisible characters shown; my guess is it'll print alias sbp='source ~/.bash_profile^M' (where the ^M is cat -vt's way of representing the carriage return).
Solution: convert the file to unix format, and either switch to a text editor that knows how to save in unix format, or change your settings in the current editor to do it. For conversion, there are a number of semi-standard tools like dos2unix and fromdos. If you don't have any of those, this answer has some other options.
BTW, the reason the error message is garbled is that the CR gets printed as part of the error message, and the terminal treats that as an instruction to go back to the beginning of the line; it then prints the rest of the message over top of the beginning of the message. It's a little like this:
-bash: /home/dir/path/.bash_profile
: No such file or directory
...but with the second line printed over the first, so it comes out as:
: No such file or directory_profile

How to paste multi-line input into Jupyter console?

The %paste magic for pasting multi-line input works with IPython 2, but fails with Jupyter console (on Mac OSX El Capitan).
~ > jupyter console
Jupyter Console 4.1.0
In [1]: %paste
ERROR: Line magic function `%paste` not found.
In [2]:
Going through the output of %lsmagic that lists all the magic commands indeed doesn't show %paste.
I tried to directly paste, but the indentation gets messed up, so something like %paste is needed apparently. Checking the official documentation (updated just 5 days ago) the word "paste" is not even mentioned.
So, how do you paste multi-line input to the console?
Ok. Found the solution. Jupyter console has a %cpaste magic that behaves a little different than the previous %paste but get the job done.
%cpaste:
Paste & execute a pre-formatted code block from clipboard.
You must terminate the block with '--' (two minus-signs) or Ctrl-D
alone on the line. You can also provide your own sentinel with '%paste
-s %%' ('%%' is the new sentinel for this operation).
The block is dedented prior to execution to enable execution of method
definitions. '>' and '+' characters at the beginning of a line are
ignored, to allow pasting directly from e-mails, diff files and
doctests (the '...' continuation prompt is also stripped). The
executed block is also assigned to variable named 'pasted_block' for
later editing with '%edit pasted_block'.
You can also pass a variable name as an argument, e.g. '%cpaste foo'.
This assigns the pasted block to variable 'foo' as string, without
dedenting or executing it (preceding >>> and + is still stripped)
'%cpaste -r' re-executes the block previously entered by cpaste.
'%cpaste -q' suppresses any additional output messages.
Do not be alarmed by garbled output on Windows (it's a readline bug).
Just press enter and type -- (and press enter again) and the block
will be what was just pasted.
IPython statements (magics, shell escapes) are not supported (yet).
See also
--------
paste: automatically pull code from clipboard.
Examples
--------
::
In [8]: %cpaste
Pasting code; enter '--' alone on the line to stop.
:>>> a = ["world!", "Hello"]
:>>> print " ".join(sorted(a))
:--
Hello world!

A simle Perl code with here-document works on Linux but not on Windows

While practicing I found that the following code is working fine on Linux but not on Windows
print<<EOF;
this is a paragraph
EOF
On Windows it says.
Can't find string terminator "EOF" anywhere before EOF at demo.pl.
Windows thinks the end of file is part of the terminating string EOF, thus it doesn't follow the rule that The terminating string must appear by itself. You need to add a new line after the terminating string EOF.
print<<EOF;
this is a paragraph
EOF
# a new line

How to make the specified command run in vim?

I know how to make shell command run in vim,in command mode,type
:!shell_command
Now, I have a command in line 16 of a file open in Vim.
cp /home/debian/Downloads/rar/rar /usr/local/bin
How can I run this command in vim, without typing all of it?
When I hit :! to open up the ex command line and then use <C-r>", I get this:
ls /tmp^m
I have to erase ^m with the backspace key, and press the enter key, is that right?
can i not to let ^M to be shown ?
To run the command on the line your cursor is on you can yank the line into you clipboard. Type :! to open up the ex command line and then use <C-r>" to paste the command onto the command line.
So with the cursor on the line type and hit enter.
yy:!<C-r>"
Take a look at :h <c-r>.
CTRL-R {0-9a-z"%#:-=.} *c_CTRL-R* *c_<C-R>*
Insert the contents of a numbered or named register. Between
typing CTRL-R and the second character '"' will be displayed
to indicate that you are expected to enter the name of a
register.
The text is inserted as if you typed it, but mappings and
abbreviations are not used. Command-line completion through
'wildchar' is not triggered though. And characters that end
the command line are inserted literally (<Esc>, <CR>, <NL>,
<C-C>). A <BS> or CTRL-W could still end the command line
though, and remaining characters will then be interpreted in
another mode, which might not be what you intended.
Special registers
Simple answer:
:exec '!'.getline('.')

In bash, how do I bind a function key to a command?

Example: I want to bind the F12 key to the command echo "foobar" such that every time I hit F12 the message "foobar" will be printed to screen. Ideally it could be any arbitrary shell command, not just builtins. How does one go about this?
You can determine the character sequence emitted by a key by pressing Ctrl-v at the command line, then pressing the key you're interested in. On my system for F12, I get ^[[24~. The ^[ represents Esc. Different types of terminals or terminal emulators can emit different codes for the same key.
At a Bash prompt you can enter a command like this to enable the key macro so you can try it out.
bind '"\e[24~":"foobar"'
Now, when you press F12, you'll get "foobar" on the command line ready for further editing. If you wanted a keystroke to enter a command immediately, you can add a newline:
bind '"\e[24~":"pwd\n"'
Now when you press F12, you'll get the current directory displayed without having to press Enter. What if you've already typed something on the line and you use this which automatically executes? It could get messy. However, you could clear the line as part of your macro:
bind '"\e[24~":"\C-k \C-upwd\n"'
The space makes sure that the Ctrl-u has something to delete to keep the bell from ringing.
Once you've gotten the macro working the way you want, you can make it persistent by adding it to your ~/.inputrc file. There's no need for the bind command or the outer set of single quotes:
"\e[24~":"\C-k \C-upwd\n"
Edit:
You can also create a key binding that will execute something without disturbing the current command line.
bind -x '"\eW":"who"'
Then while you're typing a command that requires a username, for example, and you need to know the names of user who are logged in, you can press Alt-Shift-W and the output of who will be displayed and the prompt will be re-issued with your partial command intact and the cursor in the same position in the line.
Unfortunately, this doesn't work properly for keys such as F12 which output more than two characters. In some cases this can be worked around.
The command (who in this case) could be any executable - a program, script or function.
You can define bash key bindings in ~/.inputrc (configuration file for the GNU Readline library). The syntax is
<keysym or key name>: macro
for example:
Control-o: "> output"
will create a macro which inserts "> output" when you press ControlO
"\e[11~": "echo foobar"
will create a macro which inserts "echo foobar" when you press F1... I don't know what the keysym for F11 is off hand.
Edit:
.inputrc understands the \n escape sequence for linefeed, so you can use
"\e[11~": "echo foobar\n"
Which will effectively 'press enter' after the command is issued.
This solution is specific to X11 environments and has nothing to do with bash, but adding the following to your .Xmodmaps
% loadkeys
keycode 88 = F12
string F12 = "foobar"
%
will send the string "foobar" to the terminal upon hitting F12.
I wanted to bind Ctrl+B to a command. Inspired by an answer above, I tried to use bind but could not figure out what series of cryptic squiggles (\e[24~ ?) translate to Ctrl+B.
On a Mac, go to Settings of the Terminal app, Profiles -> Keyboard -> + then press the keyboard shortcut you're after and it comes out. For me Ctrl+B resulted in \002 which i successfully bound to command
bind '"\002":"echo command"'
Also, if you want the command to be executed right-away (not just inserted in to the prompt), you can add the Enter to the end of your command, like so:
bind '"\002":"echo command\015"'

Resources