I have a shell script with this code:
var=`hg st -R "$path"` if [ -n "$var" ]; then echo $var fi
But the conditional code always executes, because hg st
always prints at least one newline character.
- Is there a simple way to strip whitespace from
$var
(liketrim()
in PHP)?
or
- Is there a standard way of dealing with this issue?
I could use sed or AWK, but I’d like to think there is a more elegant solution to this problem.
Related Posts:
- How to trim whitespace from a Bash variable?
- Extract substring in Bash
- “[ ]” vs. “[[ ]]” in Bash shell
- bash : Bad Substitution
- Extract filename and extension in Bash
- What is lexicographical order?
- C++ — expected primary-expression before ‘ ‘
- Regex not operator
- working of \n in python [duplicate]
- Regex not operator
- Extract a substring using PowerShell
- Regex not operator
- How to compare strings in Bash
- What is the difference between \r\n, \r, and \n? [duplicate]
- string to string array conversion in java
- What is the difference between \r\n, \r, and \n? [duplicate]
- Multi-line string with extra space (preserved indentation)
- Regex how to match an optional character
- How to remove punctuation in python?
- Multi-line string with extra space (preserved indentation)
- How do I properly compare strings in C?
- How to remove .html from URL?
- What is the difference between a “line feed” and a “carriage return”?
- How to convert an int to string in C?
- Python: TypeError: cannot concatenate ‘str’ and ‘int’ objects
- Ignoring upper case and lower case in Java
- How to replace all double quotes to single quotes using jquery?
- Convert character to ASCII numeric value in java
- How to check if a variable is set in Bash?
- What does strcmp() exactly return in C?
- Generate random string/characters in JavaScript
- How to get the filename without the extension from a path in Python?
- sprintf like functionality in Python
- C – The %x format specifier
- Lua string.format options
- n-grams in python, four, five, six grams?
- Pass variable from one Jenkins stage to others in sh
- Alphabet range in Python
- Mixing a PHP variable with a string literal
- C++ String Variable Declaration
- How can I match a string with a regex in Bash?
- How to check if type of a variable is string?
- What does ${} (dollar sign and curly braces) mean in a string in Javascript?
- What is the difference between ‘ and ” in JavaScript?
- Center text in fixed-width field with stream manipulators in C++
- C# – Illegal characters in path
- \n or \n in php echo not print [duplicate]
- How can I print variable and string on same line in Python?
- Mips how to store user input string
- PadLeft function in T-SQL
- Create timestamp variable in bash script
- How to convert a string to lower case in Bash?
- How to modify a global variable within a function in bash?
- How to modify a global variable within a function in bash?
- How to assign multiple lines string in Powershell Console
- How to interpolate variables in strings in JavaScript, without concatenation?
- LC-3 STR with R1 as offset
- Lua read beginning of a string
- How do I remove the file suffix and path portion from a path string in Bash?
- How do I print my Java object without getting “SomeType@2f92e0f4”?
- How can I process each letter of text using Javascript?
- Fastest way to remove first char in a String
- PHP to write Tab Characters inside a file?
- How to delete specific characters from a string in Ruby?
- Haskell: Converting Int to String
- How to split one string into multiple strings separated by at least one space in bash shell?
- Passing string to a function in C – with or without pointers?
- Lua String replace
- Trim a string in C [duplicate]
- How to remove first character from C-string?
- Standard function to replace character or substring in a char array?
- Difference between char* and char** (in C)
- Meaning of #{ } in Ruby?
- Taking a new line using printf in java? Is %n correct?
- How to count instances of character in SQL Column
- How do I pause my shell script for a second before continuing?
- TypeError: a bytes-like object is required, not ‘str’ when writing to a file in Python3
- How do I compare strings in Java?
- How do I compare two strings in python?
- What is the difference between char s[] and char *s?
- Append integer to beginning of list in Python
- Check if a variable is a string in JavaScript
- What is the meaning of 2 in 2> /dev/null
- How to reload .bash_profile from the command line?
- Given two directory trees, how can I find out which files differ by content?
- How to print elements from array with javascript
- How do I check if there are duplicates in a flat list?
- c++ convert string to hex
- Is there a TRY CATCH command in Bash
- int cannot be converted to string?
- What does the @ symbol before a variable name mean in C#?
- JavaScript check if variable exists (is defined/initialized)
- How can I test that a variable is more than eight characters in PowerShell?
- How do I add a newline using printf?
- zip error – Nothing to do
- How to add multiple custom URL variables?
- Cannot get grandparent object
- How to fix Uninitialized string offset: error on a checkbox in WP Settings API
- How to display variables from plugin?
- Use a select box to change a php variable