Linked Questions
405 questions linked to/from Why is printf better than echo?
1
vote
1
answer
55
views
Why does substring expansion [ test="-efoo"; echo ${test:0:2} ] fail?
On Linux Mint, using bash..
test="-ffoo"; echo ${test:0:2}
works outputting the first two characters
but
test="-efoo"; echo ${test:0:2}
fails, with apparently null output.
I'm thinking the form ...
1
vote
2
answers
84
views
Update rows by referring another file
I have two comma separated files as mentioned below,
cat source.txt
A,1000
B,3000
C,2500
D,5000
E,4000
F,3000
cat test.txt
A,1000
C
D,5000
B
E
How can I update file test.txt by referring file source....
1
vote
3
answers
103
views
Output of find differs between direct invocation and bufferin in shell variable
I have come across some odd behaviour while using the find command that I cannot find an explanation for.
I have a .txt file with 1 filename per line and I am using the find command to recursively ...
0
votes
0
answers
118
views
echo incorrectly interpreting colors
I want my terminal prompt to change color depending on success of the previous command. Currently I achieve this with the following script:
exitstatus()
{
if [[ $? == 0 ]]; then
echo -e &...
0
votes
1
answer
78
views
Bash function can't seem take in directories with spaces in them [duplicate]
I created the following function is ~/.bashrc:
function cl {cd $1; echo $1; ls -al $1}
(I put the echo command in there just to see what it's actually reading in)
In my home directory, I created a ...
-1
votes
2
answers
197
views
How to interpret escape characters in a string and display them as newlines, color etc
i grep something like:
str='"a\nb"'
echo ${str} | grep -E -o '".*"'
and got:
"a\nb"
i wish the result displays like:
a
b
how could this be done? thanks
p.s. actually, ...
-1
votes
2
answers
79
views
Avoid bash to interpret \ in a double quoted string
I would like to be able to do something like this
VAR='\\'
echo "$VAR"
and get as result
\\
The result that I actually have is
\
Actually, I have a very long string with many \\ and when ...
0
votes
1
answer
68
views
Spaces inserted in concatenated strings despite use of braces
I used the following syntax to read in a file name and modify its extensions to generate the name of a matched data file. As an example, I have ABC_1.fastq.Blockxy, XYZ_1.fastq.Block34 and I want to ...
0
votes
1
answer
69
views
Change in shell script
I was using a bash script to do some automated testing on a CLI. All of a sudden it does not seem to work. Seems like our devops have done some changes to the OS.
The error i see is
bash-3.2$ sh ...
0
votes
1
answer
71
views
Custom IFS changed printf formatting
I have a script that needs to format numbers with thousands separators. So 1234567 becomes 1,234,567. I use printf "%'d" 1234567 to get the result. Works fine. Later in the script I set ...
0
votes
0
answers
91
views
inserting colored properties into files
when it comes to the echo -e command, of course you can do a lot with it when it comes to printing color text, especially when it comes to making terminal based UIs, but I have one main question, does ...
0
votes
0
answers
76
views
BASH: splitting status phrase of the code execution using echo -n
As a part of my bash routine I am printing some message in terminal regarding status of the workflow. The message in splited into two parts (part 1: begining of the task, part 2: status of its ...
0
votes
2
answers
68
views
How to add a path to PATH that involves a variable that needs to be evaluated?
say I want to add the current directory to path. I need to run echo "export PATH=$PATH:$(pwd)" >> ~/.bash_profile.
this expands $(pwd) like I wanted, but it also expands the $PATH ...
0
votes
0
answers
43
views
Difference between echo -e and echo -e " " [duplicate]
What is the difference between running the echo command with argument passed in quotes v/s without quotes?
echo -e hi\n # Output = hin
echo -e "hi\n" # output = hi (with extra new line)
...
0
votes
1
answer
40
views
Extract end of sub-directory names in directory
I have example sub-directory names such as:
Test_ABCDEF_406_1
Test_ABCDEF_AOH_1
Test_ABCDEF_AUQ_1
within a larger directory called Test.
How can I efficiently pull out "ABCDEF_**_" or ...