I want to use user input of special characters in conditional statement. I tried:
read -p "press arrow up" foo
if [ $foo == "^[[A" ]; then echo yes; fi
It did not do what I wanted it to do.
I want to use user input of special characters in conditional statement. I tried:
read -p "press arrow up" foo
if [ $foo == "^[[A" ]; then echo yes; fi
It did not do what I wanted it to do.
I can append text below current line, using the sed
editor:
$ foo=bar
$ echo "some text"|sed "a\bar"
some text
bar
But when I try to append text from variable below current line, using sed
, I am not able to do it:
$ foo=bar
$ echo "some text"|sed "a\$foo"
some text
$foo
Inside each dir there is a link to this dir itself:
ls -a <any dir> | head -2
$.
$..
Question: for which purposes "." aka the link to itself exists?
$ cat x
cat: x: No such file or directory
$ cat y
This is y.
$ cat x y 1> hold 2>&1
cat: x: No such file or directory
This is y.
Why stder got redirected to hold as well? stder got declared as stdout after redirecting stdout into hold and there is no more redirect after declaring happened.
I have two for loops:
for i in 0 1 2 3; do echo $i;done
for j in a b c d; do echo $j;done
0
1
2
3
a
b
c
d
I want the output be:
0
a
1
b
2
c
3
d
How to do it?
There is a string, which contains numbers and letters in its name. The symbol '_' divides different parts of the string.
X23X_1XY4_XXXX_Y12Y_YYX2_XXYY
I want to have only second, third and forth parts:
1XY4_XXXX_Y12Y
Using cut one can do:
echo 'X23X_1XY4_XXXX_Y12Y_YYX2_XXYY' | cut -d'_' -f2,3,4
How to do it with sed?
In many Linux books is written that 'redirection is executed before a command'. Let's consider:
$ cat bar
hello
$ ecno "foo" > bar
bash: ecno: command not found
$cat bar
But it does not copy any output into bar (since there is no output), so it should be said 'redirection is executed PARTIALLY before a command', since the one part of '>' did not work here, namely copying the output of the command into a file bar. Is it right?
I read in a textbook that sort command accepts input either from a file named on the command line or from standard input. I know about cat command accepting stdin:
$ cat
stdin
stdin
What can be an example of it with sort command?
I have a file.
$ cat file
"bar": false
"foo": false
I need to replace the word false
with true
only in the pattern "foo": false
. The problem is quotes and spaces.
I thought about two ways:
An example try of 2 option:
$ sed -i 's/\(.*foo\)/false/true\1/g' file
It failed.
The grep
command gives out an exit status:
$echo "foo.bar" | grep -o foo
foo
$echo $?
0
$echo "foo.bar" | grep -o pop
$echo $?
1
But I need to use sed
and I realized that it has no exit status:
$echo "foo.bar" | sed 's/bar.*$//'
foo.
$echo $?
0
$echo "foo.bar" | sed 's/pop.*$//'
foo.bar
$echo $?
0
I know that I should play around with the -q
option, but I have not succeeded.
I want to insert into alias different possible variants of spelling, for example, cat
command. Can I do it using some symbol for 'or' or should it be on a new line?
alias at|cart|cst '/bin/cat'
How do I cut all characters after the last '/'?
This text
xxxx/x/xx/xx/xxxx/x/yyyyy
xxx/xxxx/xxxxx/yyy
should return
xxxx/x/xx/xx/xxxx/x
xxx/xxxx/xxxxx
I have strings:
fvvDataFolders/DDB/DDB2018-02-21oM]
fbbDataFolders/DDB/DDB2018-02-22oM]
I want to strip everything that starts with Data and ends in what looks like a date:
DataFolders/DDB/DDB2018-02-21
DataFolders/DDC/DDB2018-02-22
How I can do it?
I want to cut a string with brackets using sed
.
How to avoid an error if I want to drop a string with [
?
For example:
$ echo '[Om/mystring' | grep -oP '(?<=[Om\\)\w+'
grep: missing terminating ] for character class
I have two different regular files: myscript2 and myscript3 with word 'dash' inside. I want to grep them, but because of '-r' addition to grep I got hidden files as well. I tried to use 'grep -v' after pipe to get rid of hidden files. I failed. Why? What to do to solve my problem?
$ ls
myscript2
myscript3
$ cat myscript2
dash
$ grep -r -l 'dash' | grep -v '^.*'
I use the realpath
command, but it always adds the original input at the end of the path:
$ pwd
/homes/yosefkl
$ realpath yosefkl
/homes/yosefkl/yosefkl
I want my bash to print 'found' only if something is found, using the find command. But using && does not help: even if found nothing, I'm getting 'found' printed. Example:
$ pwd
/data/data/com.termux/files/home/test/test1/test4
$ ls
xaa xab
$ find . -name xac && echo 'found'
found
$ find . -name xaa && echo 'found'
./xaa
found
I tried to do in tcsh the following:
$ echo $(pwd)
It does not work.
I have a function in bash to kill all the processes, which contain the same name:
killn () { pkill -9 -f $1; }
I realize that tcsh does not support functions.
How I can translate this function into an alias that will work in tcsh?
Can I use a link to a file to set a crontab job on it?
I tried the following:
$ crontab -e
$ 10***** /path-to-link/