Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Thread Tools Display Modes
Old 5th March 2011, 13:20
vl72 vl72 is offline
Junior Member
Join Date: Feb 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Question Some questions about commands in bash script

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:
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 ]    
	    echo 'Yes!'
	    echo 'No!'
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.
Reply With Quote
Sponsored Links
Old 6th March 2011, 22:23
falko falko is offline
Super Moderator
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,751 Times in 2,581 Posts

Please try double quotes instead of single quotes:
var_2="File\ with\ some\ words\ in\ it.txt"
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot login to phpmyadmin penkku HOWTO-Related Questions 1 24th February 2011 10:26
Companion Script #2 for The Perfect Server - Fedora 13 x86_64 [ISPConfig 3]" MrCompTech Tips/Tricks/Mods 0 10th July 2010 06:11
i am having some problem ? cobro Installation/Configuration 20 30th April 2008 17:26
Cannot log onto pop3 server Debian Etch Perfect Server docean Installation/Configuration 2 19th March 2008 01:23
https protocol stops page load tjd General 7 18th November 2007 19:06

All times are GMT +2. The time now is 18:54.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.