LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-08-2022, 06:40 AM   #1
nour_
LQ Newbie
 
Registered: Sep 2022
Posts: 4

Rep: Reputation: 0
Backslash in bash scripting


Hello everyone,
I see the following syntax used a lot, I know each command separately but what does the backslash do exactly?

sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release

thank you so much
 
Old 10-08-2022, 06:48 AM   #2
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,616

Rep: Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554

The backslash escapes the following newline, so the multiple lines will be treated as a single line.

Such syntax is usually used when lines would otherwise be long/unwieldy, to help readability and/or maintainability.

What you posted is the same as the single command:
Code:
sudo apt-get install ca-certificates curl gnupg lsb-release
This is described in section 3.1 of the Bash Manual (specifically 3.1.2.1) - it's a good idea for anyone using Bash to read at least Section 3.1 to understand the basics.


(Also, whilst not relevant here, BashFAQ and ShellCheck are useful resources for anyone doing Bash scripting.)


Last edited by boughtonp; 10-08-2022 at 06:58 AM.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Beginners Guide to Command Substitution in Bash (And the Backslash Mystery) LXer Syndicated Linux News 0 01-23-2020 06:11 PM
[SOLVED] Question on shell scripting: grep with backslash rookee Linux - Newbie 6 06-10-2015 01:30 PM
Meaning of backslash in bash within here document and command substitution moraxu Linux - Newbie 2 04-02-2013 12:51 PM
The sed bash command, not print backslash in Perl azkarashare Programming 8 07-12-2010 06:58 AM
converting Dos link backslash to Unix like backslash barunparichha Linux - Software 1 05-14-2009 09:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration