Skip to content
Advertisement

Tag: shell

Commands terminated with the same char

How can I fix the follow line: The problem is that the commands of for and -exec end with a semicolon, the for command has this statement and find statment with -exec Answer You don’t even need to use -exec echo {} since that is default action in find. You can use this for loop: There is no need to

Shell script doesn’t work when I export a variable inside it

I have a script called installscript which needs a change to the PATH variable. BuildScript file has the following code: Running ./BuildScript or source BuildScript fails with an error in installscript I have made a NewScript and call BuildScript from it after exporting the PATH variable running source NewScript works. I don’t understand why running BuildScript alone won’t work. Answer

Undersired echo truncate in sh Linux

I want to send two variables as input to another command in shell script. I have tried many methods to send the two variables but I am getting unexpected problems with echo command. the above string gives unexpected truncated output.i am getting the Variables after reading from a file.(ex : HOURS1=cat time_now |cut -d ‘.’ -f 1 ) I have

How to achieve a mirror copy in Linux?

I want to make two directories synchronized. I know there is a robocopy /MIR command in Windows that can achieve this. Ex: When there is a file updated or deleted, the backup directory can keep synchronization. I have tried in Linux through the rsync command like this: but when I delete a file under /usr/test and then run this command,

How to find random files in Linux shell

How to pick 100 files randomly from a directory by Linux shell. I read other topic, ‘shuf’ command can do this: find . -type f | shuf -n100, but our environments do not have ‘shuf’ cmd. Is there other method to do this? use bash, awk, sed or sth else? Answer This should work on your CentOS5: This comes from

Running shell script using .env file

I am fairly new to running scripts in UNIX/Linux. I have a .env file containing environment information and a .sh script containing folder creations etc for that environment. How would I run the script on the environment contained in the .env file or how could I point the script to the target environment? Would it be as easy as: Answer

running bash piped comand from mono linux

I am trying to run bash command with pipe using mono process start here is code snippet I am trying single commands works, however pipe commands fails to run, what am I missing here ? I tried running “ps -aux” which runs fine. However ps -aux | grep gnome command failed. I tried these scenarios scenario 1: command = ps

Nested grep with SSH

I have a following Shell command which runs successfully: However, I have to SSH to a particular machine to run this. To avoid this, I modified it in following way which leads to the failure: What is wrong with this command? How can I fix this? Answer Embed your code in a quoted heredoc to avoid needing to modify it

Can’t use multiplication in arithmetic expression

The above is the content of calculate.sh. If I use +, -, or /, I get the correct answer, but when I use *, it reports an error: How can I resolve this problem? Answer The problem was as pointed by others the fact than the character * is interpreted by your shell, be it in your terminal or your

Advertisement