Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
6
votes
8
answers
14700
views
Check if shell variable contains an absolute path
I want to check if a shell variable contains an absolute path. I don't care if the path exists or not—if it doesn't I'm going to create it—but I do want to ensure that I'm dealing with an absolute pathname. My code looks something like the following: myfunction() { [ magic test to see if "$1" is an...
I want to check if a shell variable contains an absolute path.
I don't care if the path exists or not—if it doesn't I'm going to create it—but I do want to ensure that I'm dealing with an absolute pathname.
My code looks something like the following:
myfunction() {
[ magic test to see if "$1" is an absolute path ] || return 1
mkdir -p "$(dirname "$1")" || return 1
commands >> "$1"
}
Or, the use case where the absolute path to be verified is intended to be a directory:
anotherfunction() {
[ same magic test ] || return 1
mkdir -p "$1"
dostuff >> "$1/somefile"
}
If this were
awk
I would do the check like so: myvar ~ /^\//
There *must* be a clean way to do this with the shell's string handling, but I'm having trouble coming up with it.
(Mentioning a bash
-specific solution would be fine but I'd like to know how to do this portably, also. POSIX string handling seems like it should be sufficient for this.)
Wildcard
(37446 rep)
Jan 20, 2016, 12:57 AM
• Last activity: Jul 20, 2025, 07:52 AM
2
votes
1
answers
57
views
Want to search for a every paragraph that has a certain string and return some string from that paragraph
``` /* ----------------- WANT TO RETURN1 ----------------- */ machine: some value server: WANT TO RETURN1 owner: some value notification: some value informatica: some value sap: some value group: This line contains a3 but can have space and characters /* ----------------- WANT TO RETURN2 -----------...
/* ----------------- WANT TO RETURN1 ----------------- */
machine: some value
server: WANT TO RETURN1
owner: some value
notification: some value
informatica: some value
sap: some value
group: This line contains a3 but can have space and characters
/* ----------------- WANT TO RETURN2 ----------------- */
server: WANT TO RETURN2
machine: some value
owner: some value
notification: some value
informatica: some value
sap: some value
group: This line contains a1 but can have space and characters
unix: some value
windows: some value
aws: some value
sap1: some value
/* ----------------- WANT TO RETURN3 ----------------- */
owner: some value
machine: some value
server: WANT TO RETURN3
notification: some value
informatica: some value
sap: some value
group: This line contains a1 but can have space and characters
/* ----------------- WANT TO RETURN4 ----------------- */
server: WANT TO RETURN4
machine: some value
owner: some value
notification: some value
informatica: some value
sap: some value
group: This line contains a2 but can have space and characters
unix: some value
windows: some value
aws: some value
sap1: some value
Need to do with linux shell script if possible.
I have some data in unix file as above.
I have a file with multiple values for _STRING_TO_SEARCH
_ like
job.txt
:
a1
a2
a3
Example -
I want to run a for loop for each value of _STRING_TO_SEARCH
_ and capture both _STRING_TO_SEARCH
_ and server:
value for that paragraph
Desired output -
group: a1
server: WANT TO RETURN2
server: WANT TO RETURN3
group: a2
server: WANT TO RETURN4
group: a3
server: WANT TO RETURN1
In each paragraph number of rows will vary and fields server: WANT TO RETURN
and group:
. This line contains a1
but can have space or characters can can occur on any row.
user9797
(23 rep)
Jul 17, 2025, 11:12 PM
• Last activity: Jul 18, 2025, 11:08 AM
1
votes
6
answers
602
views
Change a double quote into a single quote with gnu sed when the quotes come before and after a parenthesis?
I'm using Debian 12 bookworm, gnu sed. I have this ```lang-none "Hello1" "('41-Z', 5001, 'A6')" "'Hello2'" "('42-Z', 5002, 'A7')" 'Hello3' "('43-Z', 5003, 'A8')" ``` I want to modify only the lines with parenthesis entries, to appear like this: ```lang-none "Hello1" '('41-Z', 5001, 'A6')' "'Hello2'"...
I'm using Debian 12 bookworm, gnu sed. I have this
-none
"Hello1"
"('41-Z', 5001, 'A6')"
"'Hello2'"
"('42-Z', 5002, 'A7')"
'Hello3'
"('43-Z', 5003, 'A8')"
I want to modify only the lines with parenthesis entries, to appear like this:
-none
"Hello1"
'('41-Z', 5001, 'A6')'
"'Hello2'"
'('42-Z', 5002, 'A7')'
'Hello3'
'('43-Z', 5003, 'A8')'
How can I used sed to trade out the double quotes for single quotes of the lines in this example that have parenthesis, without interfering with the quotes of the other lines? This is a large text file that has hundreds, maybe thousands of these entries.
I prefer sed, but I also tried looking for answers that use tr (truncate). Maybe someone has an awk answer.
shrykullgod
(39 rep)
Jul 13, 2025, 11:18 PM
• Last activity: Jul 16, 2025, 10:07 AM
6
votes
2
answers
468
views
Can I use grep or strings to find the previous atime of a file still present on my btrfs?
The metadata of this file which resides on my HDD is written by CoW, therefore can I look for it just by using grep or strings, and the filename?
The metadata of this file which resides on my HDD is written by CoW, therefore can I look for it just by using grep or strings, and the filename?
user324831
(113 rep)
Jun 1, 2025, 10:00 AM
• Last activity: Jun 11, 2025, 08:04 PM
0
votes
3
answers
77
views
Making each word in a text file an item in a bash array
I have a string of text and spaces which looks like this: macOS windows arch-linux ubuntu_linux I want to append each item (with whitespace denoting a break between items) to a bash array. How do I do this?
I have a string of text and spaces which looks like this:
macOS windows arch-linux ubuntu_linux
I want to append each item (with whitespace denoting a break between items) to a bash array. How do I do this?
EmberNeurosis
(5 rep)
Apr 29, 2025, 01:22 AM
• Last activity: Apr 29, 2025, 07:14 AM
660
votes
26
answers
767390
views
How to generate a random string?
I would like to generate a random string (e.g. passwords, user names, etc.). It should be possible to specify the needed length (e.g. 13 chars). What tools can I use? (For security and privacy reasons, it is preferable that strings are generated off-line, as opposed to online on a website.)
I would like to generate a random string (e.g. passwords, user names, etc.). It should be possible to specify the needed length (e.g. 13 chars).
What tools can I use?
(For security and privacy reasons, it is preferable that strings are generated off-line, as opposed to online on a website.)
landroni
(11586 rep)
Sep 19, 2015, 08:06 AM
• Last activity: Apr 4, 2025, 03:21 PM
2
votes
1
answers
311
views
How can I take a sub-array in bash of the first N elements of a string array with elements containing spaces?
This question is similar to [this one][1] but it differs from it: Consider this array with string elements which may contain spaces: a@W:$ arr=("eins" "zwei" "eins plus zwei" "vier" "fünf") a@W:$ echo ${#arr[@]} # ok, 5 elements, as expected 5 a@W:$ echo ${arr[3]} # the fourth one, indexing sta...
This question is similar to this one but it differs from it:
Consider this array with string elements which may contain spaces:
a@W:$ arr=("eins" "zwei" "eins plus zwei" "vier" "fünf")
a@W:$ echo ${#arr[@]} # ok, 5 elements, as expected
5
a@W:$ echo ${arr} # the fourth one, indexing starts at 0
vier
a@W:$ echo ${arr} # the third one, which contains two blancs
eins plus zwei
a@W:$ ar2=${arr[@]:0:3} # I only want the firs three of them
a@W:$ echo ${ar2[@]}
eins zwei eins plus zwei
a@W:$ echo ${#ar2[@]} # but they are all glued together into one element
1
a@W:$
**What mus I do to prevent this gluing them all together?** The string containing spaces, "eins plus zwei" shall stay the third element.
Adalbert Hanßen
(303 rep)
Mar 24, 2025, 12:47 PM
• Last activity: Mar 24, 2025, 11:53 PM
44
votes
3
answers
157511
views
Verify the length of a variable
I've to verify the length of variable read (my script limit to five the characters inserted), I think about something like this: #!/bin/bash read string check=${#string} echo $check if [ $check -ge 5 ]; then echo "error" ; exit else echo "done" fi is there a more "elegant" solution?
I've to verify the length of variable read (my script limit to five the characters inserted), I think about something like this:
#!/bin/bash
read string
check=${#string}
echo $check
if [ $check -ge 5 ]; then echo "error" ; exit
else echo "done"
fi
is there a more "elegant" solution?
Pol Hallen
(2257 rep)
Jul 17, 2014, 05:08 PM
• Last activity: Mar 8, 2025, 09:03 AM
-1
votes
2
answers
62
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 Example: "UTF-8/CRLF" "UCS-2/CRLF/21" That is there may be only Character set name (unknown beforehand) without a...
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
Example: "UTF-8/CRLF"
"UCS-2/CRLF/21"
That is there may be only Character set name (unknown beforehand) without any "/" separator.
Character set name may contain "-" and "_" (no need to separate here).
Need to assign to:
VAR1=Character set name
VAR2=CRLF or LF part between 1st "/" and 2nd "/" (or empty string if there's no "/").
VAR3=Remainer after 2nd "/".
Some kind of true/false (0/1) for VAR2 is OK also (it will be processed with if/else later in script).
Tried
cut -d/ -f
, but cut -d/ -f 2
returns "Character set name" even **if there's no "/"**, so it doesn't work for me.
For **Bash** script a **Faster** solution is preferred as it will be run many times.
I do need to call a function as /bin/bash -c
b/c its called in find -exec
.
Code (mostly based on Choroba's answer):
#!/bin/bash
shopt -s extglob
function convert_single_text_file_to_utf8(){
CUR_FILE_ENCODING_WITH_CRLF=$1
echo "CUR_FILE_ENCODING_WITH_CRLF=${CUR_FILE_ENCODING_WITH_CRLF}"
CUR_FILE_ENCODING_ONLY=${CUR_FILE_ENCODING_WITH_CRLF%%/*} # Remove everything starting from the last slash.
LINE_FEED=${CUR_FILE_ENCODING_WITH_CRLF##$CUR_FILE_ENCODING_ONLY?(/)} # Remove the charset, followed by a slash if any.
echo "CUR_FILE_ENCODING_ONLY=${CUR_FILE_ENCODING_ONLY} LINE_FEED=${LINE_FEED}"
}
export -f convert_single_text_file_to_utf8
for ENCODING in ASCII UTF-8/CRLF ISO-8859-2/LF EBCDIC-CA-FR; do
echo "ENCODING=$ENCODING"
export ENCODING
/bin/bash -c 'shopt -s extglob; convert_single_text_file_to_utf8 "$ENCODING" '
done
strider
(43 rep)
Feb 27, 2025, 05:11 PM
• Last activity: Feb 27, 2025, 11:28 PM
0
votes
2
answers
151
views
How to check value inside a file using bash?
I'm trying to check if the value inside a file is "0". ``` COUNT_EXECUTION=$(< /tmp/count) if [ "$COUNT_EXECUTION" == "0" ]; then echo "Try restart service." else echo "There is execution in progress." fi ``` File content is just a `0`, but the test always falls into the else
I'm trying to check if the value inside a file is "0".
COUNT_EXECUTION=$(< /tmp/count)
if [ "$COUNT_EXECUTION" == "0" ]; then
echo "Try restart service."
else
echo "There is execution in progress."
fi
File content is just a 0
, but the test always falls into the else
Aderbal Nunes
(137 rep)
Feb 20, 2025, 11:54 AM
• Last activity: Feb 21, 2025, 06:11 AM
0
votes
2
answers
92
views
How to search for a newline that is not preceeded by } and remove it
I want to use `sed` to search for line breaks that are not preceded by `}`. The regex for identifying theses cases is: `[^}]$` . What I want to say: If the line ended without `}` then remove the new line. Any line should end with `}` before the newline. How to put that in `sed` to remove them? **EDI...
I want to use
sed
to search for line breaks that are not preceded by }
.
The regex for identifying theses cases is: [^}]$
. What I want to say: If the line ended without }
then remove the new line. Any line should end with }
before the newline.
How to put that in sed
to remove them?
**EDIT:**
Example:
{'Date': 'Fri, 19 Apr 2019 07:23:14 GMT', 'Server': 'Apache', 'Vary': 'Qualys-Scan', 'Strict-Transport-Security': 'max-age=31536000;includeSubDomains;preload', 'Set-Cookie': 'ASP.NET_SessionId=ivoa5bhet0s2ygkylmimvkie; path=/; secure; HttpOnly;SameSite=strict, SC_ANALYTICS_GLOBAL_COOKIE=12f133ea; expires=Thu, 19-Apr-2029 07:23:14 GMT; path=/; secure; HttpOnly;SameSite=strict, SC_ANALYTICS_SESSION_COOKIE=336B5|1|ivoa5; path=/; secure; HttpOnly;SameSite=strict, incap_ses_885_270026=cDp/VlO1AHgshF9F6SZID==; path=/; Domain=.zurich.co.uk, ___utmvm=dlNaoEsuXSO; path=/; Max-Age=900, ___utmvay=nWJx01KvGT; path=/; Max-Age=900, ___utm=JZy
XEtOwalQ: PtR; path=/; Max-Age=900', 'X-Content-Type-Options': 'nosniff', 'X-XSS-Protection': '1; mode=block', 'Cache-Control': 'private', 'Content-Type': 'text/html; charset=utf-8', 'Keep-Alive': 'timeout=5, max=10', 'Connection': 'Keep-Alive', 'X-Iinfo': '8-3925806-3807 NNNN CT(73 151 0) RT(155583 5) q(0 0 3 0) r(6 6) U5', 'X-CDN': 'Incapsula', 'Content-Encoding': 'gzip', 'Transfer-Encoding': 'chunked'}
When I applied your script, it combined the lines. However, the new line starts with tab
. How to also remove the spaces if the newline starts with spaces?
None
(219 rep)
May 11, 2019, 12:51 PM
• Last activity: Dec 29, 2024, 09:45 AM
2
votes
2
answers
4942
views
Traverse Through Space-separated String
So I ran `ips=$(arp | awk '{print $1}')` to save all the IP addresses retrieved from the `arp` command into a variable, `ips`. `echo` of `ips` gives me `Address 192.168.10.100 192.168.10.101 192.168.10.1`. I am assuming that `Address 192.168.10.100 192.168.10.101 192.168.10.1` is saved as string in...
So I ran
ips=$(arp | awk '{print $1}')
to save all the IP addresses retrieved from the arp
command into a variable, ips
. echo
of ips
gives me Address 192.168.10.100 192.168.10.101 192.168.10.1
. I am assuming that Address 192.168.10.100 192.168.10.101 192.168.10.1
is saved as string in the ips
variable. What I want is a way to loop through the variable ips
and maybe save the one in a variable, ip
, do something with it, and move to next one.
Fazle Rabbi
(556 rep)
Nov 18, 2016, 03:11 PM
• Last activity: Nov 5, 2024, 10:39 PM
0
votes
3
answers
238
views
How to edit a string matching a pattern in a specific field on the condition another string is not present on the same line
I need to edit the string "NA" to "Na" only if it is in the 6th field of a file. I can currently achieve this with: awk '{gsub("NA","Na",$6)}1' $filename However I need the additional condition that this wont occur if the string "HEM" is in the same line. For example I would want the following line...
I need to edit the string "NA" to "Na" only if it is in the 6th field of a file. I can currently achieve this with:
awk '{gsub("NA","Na",$6)}1' $filename
However I need the additional condition that this wont occur if the string "HEM" is in the same line. For example I would want the following line to stay the same:
7353 NA 5.4433 24.4404 -3.0784 NA 456 HEM
Lastly, the above command removes the extra padding between fields. If there is a command that can accomplish this without changing the spacing between fields that would be awesome, but this feature is not necessary.
I think this could be done with a while read through each file and printing each line, and only editing with an if statement, but I am trying to avoid something clunky like that.
I feel like this one is a tall order to do in a simple fashion, but I would be super appreciative if any unix wizards know how. Thanks!
CPC_92
(3 rep)
Oct 29, 2024, 11:42 PM
• Last activity: Nov 1, 2024, 08:08 PM
3
votes
2
answers
6748
views
Interpolate within single quotes
I have the following: COMMENT="A random comment" TEXT_JSON='{"person" : "Jim","comment" : "$COMMENT"}' echo "$TEXT_JSON" | jq . This prints { "person": "Jim", "comment": "$COMMENT" } which is not what I want. How can I interpolate the string here?
I have the following:
COMMENT="A random comment"
TEXT_JSON='{"person" : "Jim","comment" : "$COMMENT"}'
echo "$TEXT_JSON" | jq .
This prints
{
"person": "Jim",
"comment": "$COMMENT"
}
which is not what I want. How can I interpolate the string here?
Jim
(1479 rep)
Jun 5, 2018, 11:16 AM
• Last activity: Oct 22, 2024, 09:01 AM
0
votes
3
answers
322
views
Convert json data to comma separated string
I have a json object that has an unknown number of variables, like this: ``` { "var1": 123, "var2": 456, "var3": 789 } ``` How can I automatically convert it to form the following string? ``` 'var1=123,var2=456,var3=789' ``` Note, I am looking for a solution that doesn't require installing jq.
I have a json object that has an unknown number of variables, like this:
{
"var1": 123,
"var2": 456,
"var3": 789
}
How can I automatically convert it to form the following string?
'var1=123,var2=456,var3=789'
Note, I am looking for a solution that doesn't require installing jq.
teeeeee
(305 rep)
Oct 12, 2024, 08:11 PM
• Last activity: Oct 13, 2024, 07:21 AM
0
votes
1
answers
84
views
Problem matching new terminal window ID with xdotool in Bash
I have a script that kicks off a new terminal window that I want to move to a specific position on the left terminal using xdotool. After kicking off the terminal I run xdotool search --class gnome-term and I use the returned Window ID in the xdotool windowsize and windowmove commands to size and po...
I have a script that kicks off a new terminal window that I want to move to a specific position on the left terminal using xdotool.
After kicking off the terminal I run
xdotool search --class gnome-term
and I use the returned Window ID in the xdotool windowsize and windowmove commands to size and position the new terminal window.
xdotool windowsize $WIN_ID 1978 407
xdotool windowmove &WIN_ID -26 702
Since I have multiple terminals running I need to identify which WIN_ID is associated with the last terminal window just created.
In the script I execute the below command before launching the new terminal to get a list of existing WIN_IDs.
for i in
xdotool search --class gnome-term
; do id_list="$id_list $i"; done
Sample content of $id_list:
65011713 65011722 65103242 65019818 65029314 65027106
After launcing the new terminal, to identify the new WIN_ID, I run this test.
for WID in xdotool search --class gnome-term
; do if [[ ! $WID =~ $id_list ]]; then echo "New Window ID = $WID"; fi; done
When I run this command, instead of getting just one (the new) Window ID, I get all the Window IDs associated with the gnome-terminal class. Why is the below command not returning only the WID that isn't in id_list?
if [[ ! $WID =~ $id_list ]]; then ...
Script:
...
...
# Generate a list of Window IDs for existing gnome-terminal windows
for i in xdotool search --class gnome-term
; do id_list="$id_list $i"; done
# Kick off a new terminal window
gnome-terminal
# Get the Window ID of the new terminal window
New_WID=for WID in
xdotool search --class gnome-term; do if [[ ! $WID =~ $id_list ]]; then echo $WID"; fi; done
...
...
Thanks for time and feedback!
Tex
Tex
(1 rep)
Sep 27, 2024, 06:35 PM
• Last activity: Sep 28, 2024, 08:38 AM
14
votes
5
answers
40278
views
grep substring between quotes
Let's say I have a string like this: title="2010-09-11 11:22:45Z" How can I `grep` the date itself and disregard the quotes/title/`Z`? The file can contain more strings like: randomstring title="2010-09-11 11:22:45Z" title="disregard me" So I only want to `grep` timestamps with a single `grep` comma...
Let's say I have a string like this:
title="2010-09-11 11:22:45Z"
How can I
grep
the date itself and disregard the quotes/title/Z
?
The file can contain more strings like:
randomstring
title="2010-09-11 11:22:45Z"
title="disregard me"
So I only want to grep
timestamps with a single grep
command.
polym
(11052 rep)
Jul 26, 2014, 06:16 PM
• Last activity: Sep 26, 2024, 01:39 PM
2
votes
1
answers
298
views
Joining 'fish shell' arguments into a single string with spaces
Sorry, this question is already answered for 'bash' here: [Joining bash arguments into single string with spaces][1]. [1]: https://unix.stackexchange.com/questions/197792/joining-bash-arguments-into-single-string-with-spaces in Fish, using ```"'$*'"``` leads to this error: ```$* is not supported. In...
Sorry, this question is already answered for 'bash' here:
Joining bash arguments into single string with spaces .
in Fish, using
"'$*'"
leads to this error:
$* is not supported. In fish, please use $argv.
but I can't figure out how to join $argv elements to a single string with space between them.
I also tried the "${@}"
solution, which also doesn't work.
MHM
(83 rep)
Jul 17, 2024, 06:22 AM
• Last activity: Jul 17, 2024, 01:33 PM
1
votes
2
answers
698
views
Bash displaying gibberish after specific incoming request
I set up a new, basic Linux server (CentOS in this case) just for testing purposes. In there, without any firewalls and all that I'm running a Python web application. Basically I type `python run.py` and have the application on foreground, while the application itself is run on some port like `8080`...
I set up a new, basic Linux server (CentOS in this case) just for testing purposes. In there, without any firewalls and all that I'm running a Python web application. Basically I type
python run.py
and have the application on foreground, while the application itself is run on some port like 8080
, so in web browser I use I just type my_public_ip_addr:8080
and use it just fine. All this happens over SSH from my laptop.
Now, I left my laptop open for a while, and when I came back, the shell was displaying something like this:
83.20.238.86 - - [13/Mar/2019 08:54:43] "GET / HTTP/1.1" 200 -
87.122.83.97 - - [13/Mar/2019 11:55:30] "GET / HTTP/1.1" 200 -
176.32.33.145 - - [13/Mar/2019 12:08:36] "GET / HTTP/1.1" 200 -
176.32.33.145 - - [13/Mar/2019 12:08:36] code 400, message Bad request syntax ('\x16\x03\x01\x00\xfc\x01\x00\x00\xf8\x03\x03(\xd3FM\xf5\x0eLo\x17\xa3|\x1f8\xca~#\x07\xc1\x1f&&\x14\x19\x11\x10:\x824\xd23nA\x00\x00\x8c\xc00\xc0,\xc02\xc0.\xc0/\xc0+\xc01\xc0-\x00\xa5\x00\xa3\x00\xa1\x00\x9f\x00\xa4\x00\xa2\x00\xa0\x00\x9e\xc0(\xc0$\xc0\x14\xc0')
176.32.33.145 - - [13/Mar/2019 12:08:36] "��(M�L⎺�≠8#�&&:�4┼A��▮�←�2�↓�/�→�1�↑���������(�$��" 4▮▮ ↑
176↓32↓33↓145 ↑ ↑ [13/M▒⎼/2▮19 14:55:55] "GET / HTTP/1↓1" 2▮▮ ↑
176↓32↓33↓145 ↑ ↑ [13/M▒⎼/2▮19 14:55:55] c⎺de 4▮▮← └e⎽⎽▒±e B▒d ⎼e─┤e⎽├ ⎽≤┼├▒│ ('\│16\│▮3\│▮1\│▮▮\│°c\│▮1\│▮▮\│▮▮\│°8\│▮3\│▮3\│92\│8e\│°7\│9e\│1▒\│▒2\│1e\│°8\│°bb^\│1b\│d1\│▒1\│1e\│d2\│d1^\│1e/└\│96_(\│beU\│▮4\│8d≥\│d7⎻\│°e\│▮▮\│▮▮\│8c\│c▮▮\│c▮←\│c▮2\│c▮↓\│c▮/\│c▮→\│c▮1\│c▮↑\│▮▮\│▒5\│▮▮\│▒3\│▮▮\│▒1\│▮▮\│9°\│▮▮\│▒4\│▮▮\│▒2\│▮▮\│▒▮\│▮▮\│9e\│c▮(\│c▮$\│c▮\│14\│c▮')
176↓32↓33↓145 ↑ ↑ [13/M▒⎼/2▮19 14:55:55] "���������b^[⎺⎼▒┼±e@ce┼├⎺⎽↑⎺⎼▒┼±e ⎺⎼▒┼±e_±c]$ ^C
[⎺⎼▒┼±e@ce┼├⎺⎽↑⎺⎼▒┼±e ⎺⎼▒┼±e_±c]$ ┌⎺±⎺┤├
C⎺┼┼ec├☃⎺┼ ├⎺ 1▮4↓248↓36↓8 c┌⎺⎽ed↓
▒d▒└@±⎽:·$
▒d▒└@±⎽:·$
▒d▒└@±⎽:·$
▒d▒└@±⎽:·$ ec▒⎺ '▒e┌┌⎺ ⎽├▒c┐ ⎺┴e⎼°┌⎺┬'
▒e┌┌⎺ ⎽├▒c┐ ⎺┴e⎼°┌⎺┬
▒d▒└@±⎽:·$
You can see 3 last "normal" GET requests to /
, but then it begins. I know it can be fixed (link1 or link2 ) and these were some scanning bots, but my question is:
**How does it work, that incoming request broke my terminal?**
adamczi
(261 rep)
Mar 13, 2019, 04:41 PM
• Last activity: Jul 15, 2024, 04:19 PM
17
votes
4
answers
18777
views
How to assert that a string has a newline character and, if so, remove it
I have a string that is the result of some operation I have no control over. When I print this variable using `echo`, I get: echo $myvar hello However, when I do if [ $myvar = "hello" ]; then echo they are equal else echo they are not equal fi I always get that they are not equal. I suspect this is...
I have a string that is the result of some operation I have no control over. When I print this variable using
echo
, I get:
echo $myvar
hello
However, when I do
if [ $myvar = "hello" ]; then
echo they are equal
else
echo they are not equal
fi
I always get that they are not equal. I suspect this is because of a newline
character.
The string also behaves strangely. When I do:
newVAR="this is my var twice: "$myvar$myvar
echo $newVAR
I get:
hellois my var twice: hello
How can I check if this is in fact due to a newline
and, if so, remove it?
farid99
(583 rep)
Jul 9, 2015, 10:54 PM
• Last activity: Jul 14, 2024, 02:19 PM
Showing page 1 of 20 total questions