Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

What does -n do in bash scripting

Posted on 2014-03-11
4
Medium Priority
?
411 Views
Last Modified: 2014-03-11
What does the -n after the echo mean and do and what happens if i exclude it?

echo -n "Enter no 1 : "
read no_1
echo -n "Enter no 2 : "
read no_2
echo -n "Enter no 3 : "
read no_3
echo $no_1 > no_file
echo $no_2 >> no_file
echo $no_3 >> no_file
sort -n -r no_file |sed -n '1p’

Open in new window

0
Comment
Question by:Mark_Co
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 11

Assisted Solution

by:epichero22
epichero22 earned 1000 total points
ID: 39921326
-n prevents the script from outputing the trailing newline, and I believe it will allow the user to input data on the same line rather than on a new line, if that's automatically generated.  Example:

Enter no 1 : ___

vs

Enter no 1 :
___
0
 
LVL 5

Accepted Solution

by:
Joe Jenkins earned 1000 total points
ID: 39921353
It literally means, "Do not output the following trailing new line"

Bash man echo

If you leave it off it should go to the next line after the colon.  Leaving the -n in would allow the output to stay on the same page.

The output from your script would look like this with it:
Enter no 1 : <input>
Echo no 2 : <input>
Echo no 3 : <input>

Without it:
Enter no 1 :
<input>
Echo no 2 :
<input>
Echo no 3 :
<input>

I don't have access to a linux box at the moment but I'm fairly certain that is how it will output.
0
 
LVL 5

Expert Comment

by:Joe Jenkins
ID: 39921358
Ahh, I was typing my response while epichero was posting their comment.
0
 

Author Closing Comment

by:Mark_Co
ID: 39921424
Thank you both some much. I have several questions on the subject
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question