Linked Questions
405 questions linked to/from Why is printf better than echo?
0
votes
2
answers
224
views
Trying to script with 'useradd', can't understand examples
I am trying to use useradd. I found an example of something I'd like to try and incorporate, though I can't understand specific parts.
Here is the example in entirety:
if [ $(id -u) -eq 0 ]; then
...
3
votes
1
answer
125
views
Save lines to different files based on the date
How can I force a re-evaluation of this each time?
cat > $(date '+%H-%M-%S').log
So that when I first output something it gets written to one file, and after a few seconds I make another ouput and ...
0
votes
2
answers
107
views
Trying to rename bulk folders using standard tools
I am trying to bulk rename many folders but for some reason my approach does not seem to work. I am trying to use the following script but it does nothing. I am new to programming so any suggestions ...
0
votes
2
answers
150
views
How can I use pipe in a variable referrence?
I want to extract part of string in a variable as below, but it returned bad substitution.
for i in `ls`;do echo ${i|cut -d. -f1};done
-bash: ${i|cut -d. -f1}: bad substitution
In my scenario, I ...
0
votes
1
answer
83
views
Append the arguments to a script as lines in a file
How do you append $@ or $* , each as a new line to a file?
I think I already searched for that before.
Adding a new option -i --insert-newline with possible values 1, 2, 3 or Linux, Windows, Mac to ...
0
votes
3
answers
95
views
Question about if statement format
The following code prints "Odd" no matter what number I put in, why doesn't it print "Even" when given an even number as an argument?
if [[ 'echo "$1%2" | bc' =~ 0 ]]
then
echo "Even"
else
...
1
vote
1
answer
121
views
rm prompt not working when invoked from a piped loop
I am trying to remove files from a directory by pasting their names into a while loop that will simply rm each item from the list of files given to it.
$ sponge | while read file; do echo "rm $...
0
votes
3
answers
101
views
if then statment and for each bash script
I'm attempting to write a bash script to check multiple files for a string, then if the string is found to remove it. Here is what I have, which I thought would work, but is only partly. The entries ...
1
vote
1
answer
62
views
function and pass arguments
So this is my first function:
#!/bin/bash
lets_print () {
echo hello $1
}
lets_print Earth
lets_print Mars
ready to show result
user@bash$ ./demo.sh
Hello Earth
Hello Mars
And this is my ...
0
votes
2
answers
141
views
Head function behaves differently inside an sh script and in terminal. Why?
I have variable x2 having
08PKj00000YdniC
09:59:04.53 (130409269)|SYSTEM_METHOD_EXIT|[25]|System.debug(ANY)
... many other lines from logs below
I am trying to take the first line and discard ...
0
votes
1
answer
177
views
How to read files of kind "-diary.txt-" using echo?
I have a file named "-diary.txt-", I need to get it's content. When trying to read it using echo < "-diary.txt-", it returns a blank string. I did some research, and came up ...
0
votes
1
answer
53
views
I am trying to understand what a particular echo statement does
I am trying to understand what the second echo statement does exactly (it's an existing script)..
echo "Triggering report.. "
curl -s -X POST "http://aaa.bbb"
echo -e \ '\
'
I ...
0
votes
1
answer
110
views
how to combine output values using echo & fsck
I am trying to make a functional script just using Partition Label, get that label, from the Label get the Device, and pass fsck -fy twice on each partition.
#!/usr/bin/env bash
# Filter partition by ...
0
votes
1
answer
138
views
How to set a shell variable containing a single dash '-'?
How do I set a variable in Bash Zsh with a single dash (-)?
None of these work:
x=-
x=\-
x='-'
EDIT: this seems to work fine in Bash, I was testing this with echo in Zsh which doesn't work.
1
vote
1
answer
67
views
How do I avoid this unexpected behaviour when redirecting output from echo?
I wanted to add to my hosts file easily using a one line command, but I get an unexpected result.
$ sudo sh -c 'echo -e "10.0.10.0\tserver.bananas.com\tserver" >> /etc/hosts'
$ cat /etc/hosts
-...