Sponsored Content
Homework and Emergencies Homework & Coursework Questions If statements in Linux terminal Post 302861175 by sea on Tuesday 8th of October 2013 09:52:43 AM
Old 10-08-2013
First time i see constantly used the ( for if statements, i'm used to [..

Regard 'if statements'...
[[ condition ]] && echo succeeded || echo failed

Example:
[[ -z $XDG_DESKTOP_DIR ]] && echo "Your desktop is: $XDG_DESKTOP_DIR" || echo "$HOME/.config/user-dirs.dirs not loaded yet."

Which is the same as: (note the '\', that tells the line isnt dont yet, there must be no trailing spaces!)
Code:
[[ -z $XDG_DESKTOP_DIR ]] && \
    echo "Your desktop is: $XDG_DESKTOP_DIR" || \
    echo "$HOME/.config/user-dirs.dirs not loaded yet."

Which i prefer for 'short code' like setting a variable.

The && is appending the following command if previous command returns 0/true.
The || indicates what is done if the previous condition/command failed.

Examples:
Code:
[[ ! 0 -eq $UID ]] && echo "You're not root, and we abort" && exit
[[ 0 -eq $UID ]] || echo "You're not root, but we continue anyway"
[[ 0 -eq $UID ]] && echo "Must not be root!" && exit || echo "You may pass $USER"

hth

Last edited by sea; 10-08-2013 at 11:03 AM.. Reason: uh.. wasnt asked.. but since we're on it..
 

9 More Discussions You Might Find Interesting

1. Solaris

Terminal settings from linux to solaris

When I log in from my linux workstation (CentOS4) to a solaris 8 server using SSH or telnet, the terminal settings don't seem to work well. When I tail or vi a file, I get a blank screen or no response, and I am no longer able to interact with the session. I have to type the escape sequence to... (2 Replies)
Discussion started by: tjlst15
2 Replies

2. Shell Programming and Scripting

How to have color coded Terminal display,(like linux)

Hi all, I would like to know how to have a color display in the terminal... In the sense that, In many linux terminals,we have color coded for each file type, green for executable ,blue for dirs and so on... I wanted to know how i can have the same arrangement in solaris(b-79a) I am not... (5 Replies)
Discussion started by: wrapster
5 Replies

3. Ubuntu

Error on my Linux terminal

Hi, I keep on getting the following error on my linux terminal. It did not harm my system so far, but I was wondering if this can be eliminated. { Gecko:4617): GLib-GObject-CRITICAL **: file gobject.c: line 1337 (g_object_unref): assertion `G_IS_OBJECT (object)' failed (Gecko:4617):... (2 Replies)
Discussion started by: gsabarinath
2 Replies

4. Windows & DOS: Issues & Discussions

looking for linux like tab terminal for windows

Hello all is there any free tool like linux tabbed terminal but for windows im used to work with putty and its great but i wander if there something like putty but with tabs thanks (12 Replies)
Discussion started by: umen
12 Replies

5. Linux

how to perform a system check on linux via terminal

hi im new to this and i just want to learn about linux and i just wanted to know how would i be able to perform a system check to see if a directory exists. can any one help me? (2 Replies)
Discussion started by: roozis
2 Replies

6. Homework & Coursework Questions

help with linux terminal window

Hello! I need to create a file and provide access to two users of the file under the same command in linuxs terminal window. The question is how can I do it? (3 Replies)
Discussion started by: Messe
3 Replies

7. UNIX for Dummies Questions & Answers

Is there picture based game under linux terminal?

Is there picture based game under linux terminal? Just like Supermario under DOS. (18 Replies)
Discussion started by: vistastar
18 Replies

8. UNIX for Dummies Questions & Answers

Linux terminal server?

Hello everyone, I have an interesting project I'd like to implement on a Linux server here at work. Essentially, I'd like to replace a handful of Windows servers with a single Linux server. The only task these Windows servers perform, is provide remote desktops via RDP protocol that people... (13 Replies)
Discussion started by: lupin..the..3rd
13 Replies

9. UNIX for Advanced & Expert Users

Getting the process ID of the terminal in Unix/Linux

Hi, How can we get the process id of the terminal we are using? When we logged in to unix, we have an associated terminal. we can use "tty" command to get the terminal we are using like: /dev/pts/0 I want to know the process id of this terminal. Please reply as I searched a lot but I... (8 Replies)
Discussion started by: crazybisu
8 Replies
echo(3XCURSES)						  X/Open Curses Library Functions					    echo(3XCURSES)

NAME
echo, noecho - enable/disable terminal echo SYNOPSIS
cc [ flag... ] file... -I /usr/xpg4/include -L /usr/xpg4/lib -R /usr/xpg4/lib -lcurses [ library... ] c89 [ flag... ] file... -lcurses [ library... ] #include <curses.h> int echo(void); int noecho(void); DESCRIPTION
The echo() function enables Echo mode for the current screen. The noecho() function disables Echo mode for the current screen. Initially, curses software echo mode is enabled and hardware echo mode of the tty driver is disabled. The echo() and noecho() functions control soft- ware echo only. Hardware echo must remain disabled for the duration of the application, else the behavior is undefined. RETURN VALUES
Upon successful completion, these functions return OK. Otherwise, they return ERR. ERRORS
No errors are defined. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
getch(3XCURSES), getstr(3XCURSES), initscr(3XCURSES), libcurses(3XCURSES), scanw(3XCURSES), attributes(5), standards(5) SunOS 5.11 5 Jun 2002 echo(3XCURSES)
All times are GMT -4. The time now is 04:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy