Getting String character by Character in bash

Sometimes you may need to get string character by character or need to looping through the string. In python programming language, you can do this job very easily.

See below example in python.

your_string="Hello"
for c in your_string :
        print (c)

This will give output as,

H
e
l
l
o


We can do same thing in bash shell scripting also,

see below bash shell scripting example.

#getting ord value of chars.
your_string="Hello"
echo $your_string | awk -v ORS="" '{ gsub(/./,"&\n") ; print }' | \
while read char
do
echo $char
done


Cheers.... ! Happy looping through the string !

Functions for ord and chr in bash shell scripting

In python there are couple of useful function. these are ord function and chr function.

ord function in python - it take character as an argument and return its ASCII value.

chr function - it takes integer values as an argument and returns character that is equivalent to the integer value.

I am going to introduce function to do same thing in bash shell scripting. I named it as ord.

ord() {

  LC_CTYPE=C printf '%d' "'$1"
  return $LC_CTYPE

}



My next function is chr function. it takes integer value as an argument and returns correspponding ASCII value.

chr() {
  [ "$1" -lt 256 ] || return 1
  printf "\\$(printf '%03o' "$1")"
}

My Life as a Systems Engineer

I am a Bsc. Engineering graduate in Computer Engineering who has acquired  expert knowledge in developing systems under Linux platform. I have gained 4+ years of experience in doing shell scripting, awk scripting, python, and java developing. I am professionally qualified in CCNA.

Working was fun as well as challenging day by day, where I invited most of the challenges to my life. Time to go to bed and time to wake was not according to the clock but according to the work which are pending or to find a new thing every day. It can be twelve clock in the midnight or twelve clock in the day time I was in front of the laptop programming code.


Freelance working has kept me in a high place which I took the membership in November having a good response rate, not cancelling any orders where my buyers has graduated me for Level 1.


Q6 : If you are the HRM of this company how can you prevent such scenarios?

See this post for Whole Question. 



Q6: If you are the HRM of this company how can you prevent such scenarios?

To achieve the set goals and objectives of the organization the human resources which play the major role in an organization should be managed and used in an efficient and effective way. Human resource management impact employee behavior, attitudes, performance, intelligent, skills and knowledge. The labor within the organization should be managed according to philosophies, politics, procedures and practices of Human Resource Management to get the maximized economic return from labor resources by decreasing the wastage of materials and equipment. The human resource management in an organization should be done by experts or a specially qualified person for benefits otherwise it will more lead to more strict rules and regulations and only managers people not thinking that the people are a resource which can be developed and trained to retrain for a long period of time which will be very advantageous for the company’s future. HR manage always make sure the workers that they are not doing a job but it is their own career and help them grow and develop by themselves.

The HR manager should be like honey in a Bee hive where all bees get together in making the Bee hive using honey and if there is anybody doing harm all the bees get together in protecting the Bee Hive. Likewise the workers will be willingly to work towards the productivity and future of the company when HRM is integrated into business strategy. The HR Manager should be fair to all employees at any level, cooperative and always should give a helping hand for the employees in their work. He should lead the workers administrate the internal functions such as checking the attendance of workers, organizing trainings depending the training needs of the organization. He should strategically win the good will of the employees and counsel workers. He should change systematically for different situations in order to maintain the flexibility for the employees to approach. If the HRM is not integrated property it will cause high rate of resignations within a short period of time.

The motivation and interest of the employees will be a poor the employees will criticize the organization always and there will be a loss in the output.

In the case study of MR. Kamal an effective and efficient HR Manager is the first person to realize the stress that which Kamal is undergoing. He is getting absent frequently and behavior has changed when working. As a first step the HR Manager discuss about this with Mr. Kamal and understand the situation of unwillingness to report the work. He will analyze the problem and arrive at conclusions to be discussed in three different aspects. One aspect is the Management and Mr. Kamal. He is facing difficulties with the policies, rules and regulations which newly introduced or weather he needs increments, bonus, promotion or an appreciation for his 20 years of service. HR Manager should understand which one of the following be the cause and must take immediate actions having discussions with the Management. Another aspect is the sub-ordinates of Mr. Kamal. Those who are in the same level as Mr. Kamal weather they are cooperative, team work or weather the juniors make troubles for him. The HR Manager can advise them informing about the situation of Mr. Kamal to be more friendly and polite to him. One the other hand may be he is unable to carry out the duties with the new technologies or else he needs special training to carry out work. So the responsibility of HR Manager is to send Mr. Kamal for suitable trainings so that he is conversant with his work. May be his change of position as for 20 years he was handling the same correspondence and it has become boring. So HR Manager can discuss with the managers and can help to look forward changing positions. If it is his mental ill health that he is facing the stress he can be granted some leaves to take SOME and come back to work with a refreshing mind.

Q5: How will the company react on Kamal’s behaviour?

See this post for Whole Question. 



Q5: How will the company react on Kamal’s behaviour?

The Reaction of the Company can be shown in two ways. One way which will be advantageous for Mr. Kamal to continue the work without stress and the other way company will take decisions in the punitive way which is disadvantageous for Mr. Kamal.

As Mr. Kamal has worked 20 years of long service, the company has a good image of his work. The management will question him and discuss the problems he is facing at this moment. This will lead to a mutual understanding between Mr. Kamal and the management and will get some relief for his stress. On the other way the managers will be able to understand and analyze the problem of this person who has worked for 20 years with no Job Stress and why he has suddenly undergoing such a thing. The managers who have similar type of experience will counsel him on reducing “Job Stress”, engage in activities to reduce the stress, manage the responsibilities so that work load get reduced and will remain some extra time to rest. The board of managers will analyze the cases for the stress weather it is a training need, change of position, physical ill health, too much workload salary increment or problems with sub-ordinates.

The management will take necessary actions for the problems that they feel that those are the causes for Mr. Kamal’s stress immediately for the future of Mr. Kamal as well as the company as under the clause that he was a being a faithful worker.

The behavior of Mr. Kamal may have been a problem to his department or the overall productivity of the company as he has been absent for no reason. The company will give 1st warning. 2nd warning with regard to absenteeism verbally or by writing. If he continues to do so a fine also can be charged or the salary will be deducted for the no of days absent.

They also can ask for a valid medical certificate prove his sickness which he cannot provide and they will make sure that it is by purpose that he has been absent and it will automatically convert to a disciplinary auction. If the productivity of the company also had been affected he will get the last warning can lead to compulsory leave transfer, demotion and stoppage of increment and promotion. If he had to undergo punishments as such his job stress will more increased and end up in a mental illness which cause to resign from the Job or the Company will terminate him due to ill health and under disciplinary actions. The interdiction can also be a punishment taken till the announcement the date to be present for the job.