You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Cannot enter long commands in terminal

when I type long commands cursor goes back on the same line even behind the 'bash' word.

MacBook Pro 13″, macOS 10.12

Posted on Aug 5, 2020 5:52 AM

Reply
10 replies

Aug 5, 2020 6:04 AM in response to ssatiishh08

To enter multiple lines before running any of them, use Shift+Enter or Shift+Return after typing a line. This is useful, for example, when entering a set of statements containing keywords, such as if ... end. The cursor moves down to the next line, which does not show a prompt, where you can type the next line.


http://matlab.izmiran.ru/help/techdoc/matlab_env/command9.html

Aug 5, 2020 6:25 AM in response to ssatiishh08

Use the '\' character to support multi-line command syntax. Notice in the following example how it is used in white-space to force another line of input. Supported in Bash and Zsh shells. The $f in this instance is a WordPerfect file.


/Applications/LibreOffice.app/Contents/MacOS/soffice --headless \
            --convert-to docx:"MS Word 2007 XML" "$f" --outdir "$OUTFOLDER"


or with Ghostscript to split a PDF into a maximum of 10, sequentially numbered, 300 DPI png grayscale (DEVICE=pnggray) images:


# The intents set to zero is perceptual rendering
gs -q -dSAFER -sDEVICE=${DEVICE} -r$DPI -dTextAlphaBits=4 -dGraphicsAlphaBits=4 \
    -dLastPage=$page_cnt -dTextIntent=0 -dRenderIntent=0 -dImageIntent=0 \
    -dFIXEDMEDIA -dPDFFitPage -o ${BASE}_%02d.png "$1"



The operating system restricts any single command-line to a maximum of 1024 characters including the '\' character shown above.

Aug 5, 2020 4:30 PM in response to ssatiishh08

There is a very good chance your PS1 prompt string is broken.

If there are ANY characters in the PS1 prompt string that do not take up space in the prompt, then you need to bracket those characters with \[...\]


Here is my PS1

\[\$(__SetTitle ${__title}: 3)\]\D{%d%a@%R}[\[\e[44;36;1m\]BobBook_WFH\[\e[0m\]]\[\$(__vpn 1)\]\$(__vpn 2)\[\$(__vpn 3)\]\[\e[34;1m\]\$(__cwd 3)\[\e[0m\]

Yes, I know it is UGLY, but it works for me and gives a lot of information


Notice I have several places where I use \[...\] because there are escape sequences.

The \$(__SetTitle ${__title}: 3) sends the escape sequence that sets my terminal window title bar, so it takes up zero space in my command line prompt. Since the \$(...) is running a script, my terminal window title can change on each prompt, such the directory I'm in, or I'm in a source code control system view (it a work thing for me).


The \e[... are all color escape sequences.


The \$(__vpn ...) check to see if I'm VPN'ed into work or not. Again this is dynamic, so I check on each prompt.

\$(__vpn 1) outputs the RED escape sequence if I'm in a VPN session

\$(__vpn 2) outputs my visual text string (VPN) which because of the prior RED escape sequence will show up as RED, but if I'm not in a VPN, nothing comes out

\$(__vpn 3) output the turn off RED escape sequence if I'm in VPN session.


There is more, but basically the \[...\] notation is around all the terminal escape sequences that do not take up space in the command prompt.


If you forget to wrap your non-printing characters in your command prompt, you will get the behavior you are seeing.

Cannot enter long commands in terminal

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.