Guys,
I need some advice on how to check a string, which may or may not have a entry.. Never really worked out how to do this.. May be a good time to learn now.
This is what i am trying to do
Run a command, to return a string
If the string is not empty , then run the if statement, otherwise ignore
How can i write the code, so it does not give out a error message. in the form of " [: argument expected"
Note that if you use the Korn shell's built-in test ( [[ ]] ) instead of the test command, you don't need to quote the variable in order for test to "see" that value:
Output:
However, it's probably a good habit to quote it anyway in case you use another shell that does not work this way. Plus, it may help the person behind you maintaining your code. Actually, that's a good tip, while coding keep in mind the poor guy after you that has to maintain your code. :-) The more time someone has to spend figuring out your tricky code, the more expensive that program has become to maintain. Make it clear and use comments assuming the person behind you is less experienced.
Hello
So i have that script collection, in which i have a single script to create a configuration file.
In there, i have multiple occourences of something like this:
prj_title=$(tui-read "What is the TITLE? ($prj_name):")
] && prj_title="${prj_name/_/ }"
They all work as expected, if... (5 Replies)
I want to append file with a string but before doing that i want to check if this string already exist in that file.I tried with grep on Solaris 10 but unsuccessful.Man pages from grep seems to suggest if the string is found command status will be 0 and if not 1.But i am not finding it.May be i... (2 Replies)
I want to check if the string is WINDOWS-1251 or UTF-8
can you help me to find the string encoding???
or maybe to get URL Content-Type charset with wget?
this is my function on PHP
function check_utf8($str) {
$len = strlen($str);
for($i = 0; $i < $len; $i++){
$c =... (2 Replies)
I want to search a file to check if there is string a before string b:
string a, b might not necessarily be in the file, and to return a boolean
string a
(any text)
string b
i have tried for an hour to do this with perl, grep, etc. but no luck
grep doesnt search for patterns... (7 Replies)
Hi,
how to check the given string is numeric or not , without converting ( using strtol...).
for ex: if string is C01 - non-numeric data
if string is 001 - numeric data
TIA (11 Replies)
how can i check whether variable contains only character from a-z or A-Z....if my variable contains any alpha numeric, numeric or any character with some special one i.e. *%&@! etcetera etcetera....then it should show me please enter only characters......
Let my variable
var1="abc77}|"
then... (9 Replies)
Hello All,
Plz help me with:
I have a csv file with data separated by ',' and optionally enclosed by "". I want to check each of these values to see if they exceed the specified string length, and if they do I want to cut just that value to the max length allowed and keep the csv format as it... (9 Replies)
Hi I want to implement the nice command in the shell that I am building. I came to know that there is a corresponding nice() system call for the same. But since I will be forking different processes to run different commands typed on the command prompt, is there any way I can make a command... (2 Replies)
hi,
I have a variable var1 as follows in the script.
var1="one two three desformat=PDF xyz"
I would like to check whether $var1 has a string "desformat=PDF" or not.
Is there any command I can use (not need to creat a file)?
Currently, I am using this:
if ( grep "desformat=PDF"... (1 Reply)