All Questions
82 questions
-1
votes
2
answers
60
views
Split string with 0-2 / (or determine there's none) (Bash)
Update: Up to 2 "/" in the string.
String structure is either:
Character set name/LF
Character set name/CRLF
Character set name/CRLF/(unknown purpose, likely a number)
Character set name
...
0
votes
1
answer
181
views
Error in chaining multiple conditions inside a single if statement
I am working on a shell script and a part of the script should check if a file doesn't exist or if the filename provided is null (i.e. no filename has been provided).
Here is my code -
if ! [[ -e &...
0
votes
4
answers
216
views
How to remove the superfluous "./" from a path?
Consider the following script compare_times.sh (thx to http://superuser.com/a/1780500):
#!/bin/bash
# Syntax: compare_times.sh directory_1 directory_2
# Semantics: for pairs of files with the same ...
0
votes
0
answers
78
views
Creating a script which compares the return value from an AT command
I am trying to write a shell script that can save the output of a piped process to a variable. This variable is then compared to a known string in order to discern whether or not my AT modem is ...
1
vote
3
answers
108
views
get specific output in linux after string
Controller loading lists...
-------------------------------------------------
command: select SERVICE_NAME from <table_name>
-------------------------------------------------
...
2
votes
3
answers
271
views
Why do I need eval in this example?
I'm exploring the notion of having a shell script input and output two dimensional structures of strings, with the limitation that the strings do not contain newlines. They can contain spaces.
The way ...
1
vote
1
answer
208
views
IP address string manipulation problem
I am trying to build three octets 10.AB.C9 from a 5 digit number: 12ABC:
12 = first octet
AB = Second octet
C = Third octet
There are two scenarios with my existing code that can cause an in correct ...
0
votes
3
answers
166
views
Better way to convert IP?
I am trying to convert 10.AB.C9.XYZ to 10.AB.C2.252.
Right now I am extracting each character and piecing them together.
ip_main=10.AB.C9.XYZ
A_char=${ip_main:3:1}
B_char=${ip_main:4:1}
C_char=${...
0
votes
1
answer
58
views
String compare negating in bash doesn't behave as it should be?
I have this little bash script:
readonly imagick_extension=$(cat "${php_configuration_file}" | grep imagick)
echo "Imagick extension grep value: $imagick_extension"
if [ "${...
1
vote
3
answers
576
views
Encapsulate only comma-separated strings in quotes
I have some data that is currently in TSV format, but needs to be converted into CSV format. The only problem is that occasionally in the TSV, there are some values that include commas that are not ...
1
vote
3
answers
7k
views
if-statement with ((...)) string comparison not working in a bash script
I have written below script:
#!/usr/bin/bash
STR_1="nfosys"
STR_2="Infosys"
if (( $STR_1 == $STR_2 ))
then
echo "Strings are equal"
else
echo "...
1
vote
1
answer
5k
views
Putting string with newline separated words into array
I currently have a a bash variable that holds a string similar to this one,
where each different phrase is separated by a newline:
var="1st word
2nd word
4th word"
Note there is an empty ...
0
votes
0
answers
243
views
Exec Not Updating Values from Certain Bash Functions and Variables When Prepending Script Output
I am logging messages in Bash where I add some useful information to the log message to help provide context. However, in the final output most of my variables and functions appear to only use their ...
4
votes
1
answer
1k
views
Bash removes first character in for loop
I have the following code snippet:
#!/bin/bash
IFS='\r\n'
vconsole="pts"
for entry in $(last -n 10)
do
if [ -z $entry ]
then
continue
fi
if [ &...
1
vote
1
answer
612
views
Compare strings with different encodings
I'm trying to compare a string from a file that is encoded in UTF8
file /dev/eeprom: UTF-8 Unicode text, with very long lines
with a serial number that is hardcoded into the script.
When printing to ...