Skip to main content
deleted 4 characters in body
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

This looks quite verbose to me, using the command substitution and echo …echo:

# Source file
source=$( [[ ! -z "$1" ]] && echo "/home/$1" || echo '/root' )
source="$source"/.bash_history
[[ ! -f "$source" ]] && echo "History file '$source' not found." 1>&2 && exit 1;

# Am I dealing with root
isRoot=$([[ "$source" =~ ^/root ]] && echo 1 || echo 0 )

Is there a cleaner (maybe faster  ?) manner to assign a value to variable depending on some contition condition?

This looks quite verbose to me, using the command substitution and echo …:

# Source file
source=$( [[ ! -z "$1" ]] && echo "/home/$1" || echo '/root' )
source="$source"/.bash_history
[[ ! -f "$source" ]] && echo "History file '$source' not found." 1>&2 && exit 1;

# Am I dealing with root
isRoot=$([[ "$source" =~ ^/root ]] && echo 1 || echo 0 )

Is there a cleaner (maybe faster  ?) manner to assign a value to variable depending on some contition ?

This looks quite verbose to me, using the command substitution and echo:

# Source file
source=$( [[ ! -z "$1" ]] && echo "/home/$1" || echo '/root' )
source="$source"/.bash_history
[[ ! -f "$source" ]] && echo "History file '$source' not found." 1>&2 && exit 1;

# Am I dealing with root
isRoot=$([[ "$source" =~ ^/root ]] && echo 1 || echo 0 )

Is there a cleaner (maybe faster?) manner to assign a value to variable depending on some condition?

deleted 40 characters in body; edited title
Source Link
200_success
  • 144.2k
  • 22
  • 188
  • 473

Ternary like assignement in BASH Locating the Bash history file for a user

Good eveningThis looks quite verbose to me,

Given my code below using the command substitution and echo …:

# Source file
source=$( [[ ! -z "$1" ]] && echo "/home/$1" || echo '/root' )
source="$source"/.bash_history
[[ ! -f "$source" ]] && echo "History file '$source' not found." 1>&2 && exit 1;

# Am I dealing with root
isRoot=$([[ "$source" =~ ^/root ]] && echo 1 || echo 0 )

This looks quite verbose to me (using the command substitution and echo …

Is there a cleaner (maybe faster ?) manner to assign a value to variable depending on some contition ?

Ternary like assignement in BASH

Good evening,

Given my code below:

# Source file
source=$( [[ ! -z "$1" ]] && echo "/home/$1" || echo '/root' )
source="$source"/.bash_history
[[ ! -f "$source" ]] && echo "History file '$source' not found." 1>&2 && exit 1;

# Am I dealing with root
isRoot=$([[ "$source" =~ ^/root ]] && echo 1 || echo 0 )

This looks quite verbose to me (using the command substitution and echo …

Is there a cleaner (maybe faster ?) manner to assign a value to variable depending on some contition ?

Locating the Bash history file for a user

This looks quite verbose to me, using the command substitution and echo …:

# Source file
source=$( [[ ! -z "$1" ]] && echo "/home/$1" || echo '/root' )
source="$source"/.bash_history
[[ ! -f "$source" ]] && echo "History file '$source' not found." 1>&2 && exit 1;

# Am I dealing with root
isRoot=$([[ "$source" =~ ^/root ]] && echo 1 || echo 0 )

Is there a cleaner (maybe faster ?) manner to assign a value to variable depending on some contition ?

Source Link
Stphane
  • 145
  • 6

Ternary like assignement in BASH

Good evening,

Given my code below:

# Source file
source=$( [[ ! -z "$1" ]] && echo "/home/$1" || echo '/root' )
source="$source"/.bash_history
[[ ! -f "$source" ]] && echo "History file '$source' not found." 1>&2 && exit 1;

# Am I dealing with root
isRoot=$([[ "$source" =~ ^/root ]] && echo 1 || echo 0 )

This looks quite verbose to me (using the command substitution and echo …

Is there a cleaner (maybe faster ?) manner to assign a value to variable depending on some contition ?