1) Tell me, please. How to work with files and folders in BASH-script if theirs names consist of some words?
For example, name of file «File with some words in it.txt», name of folder «Folder where I saved my pictures»
When I try execute this script and file «File with some words in it.txt» doesn't exist in my home folder I receive next errors:
Code:
#!/bin/bash
cd $HOME
var_1='File with some words in it.txt'
var_2='File\ with\ some\ words\ in\ it.txt'
if [ `ls $var_2 | wc -l` -gt 0 ]
then
echo 'Yes!'
else
echo 'No!'
fi
ls: cannot access File\: No such file or directory
ls: cannot access with\: No such file or directory
ls: cannot access some\: No such file or directory
ls: cannot access words\: No such file or directory
ls: cannot access in\: No such file or directory
ls: cannot access it.txt: No such file or directory
2) How to create folder if its name consist of some words?
For example, name of folder «Folder where I saved my pictures».
3) What command can give me numeric position string character (word, phrase) that I have to search into another string from the start or from the end this string?
For example, I search word «cat» in string «Black and white dogs and cats like to eat meat» (1)
Numeric position word “cat” is 26 from the start string (1) and 21 from the end.
4) What command can append data in a new row (line) at the end of a text file? I want to direct output from cycle into the same text file. For example, this text file must have 10 lines after 10 cycle iteration, one record per line.
Recent comments
21 hours 49 min ago
1 day 2 hours ago
1 day 4 hours ago
1 day 5 hours ago
1 day 6 hours ago
1 day 11 hours ago
1 day 12 hours ago
1 day 14 hours ago
2 days 3 hours ago
2 days 5 hours ago