Glam Prestige Journal

Bright entertainment trends with youth appeal.

I have the following commands.

cd import
zcat urls1.sql.gz | mysql -u root -p urls
cd /var/www/project1/
nano 1.php

As of now I'm executing it one by one.

Is there a way to combine those commands in one line?

6

2 Answers

Yes, separate with a semi-colon like so:

dir; ls -l

Most lanugauges/shells use the semi-colon to signify the end of a command and to start new while evaluating from left to right.

Or as @RobieBasak recommends, use && instead of ; to guard against coding accidents.

dir && ls -l
2

This illustrates more:

  1. A ; B – Run A and then B, regardless of the success or failure of A

  2. A && B – Run B only if A succeeded

  3. A || B – Run B only if A failed

source :

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy