Skip to content
Advertisement

Tag: shell

How to append a column for the result set in shell script

I need a script for the below scenario. I am very new to shell script. the above query results with following result Now I need to get result as follows: 1st column, 3rd column ,4th column of above result set and new column with default values Here the last column values is always known values i.e for file1 DF.tx1 and

shell script to read values from one file and replace it in other file

I would like to replace a set of strings into a new file. Source file file1.json values has to be replaced by values from file1.config into file file2.json. I have following script that is failing to do so. file1.json file1.config run.sh Error: file2.json appears, but it has no values replaced. Answer Just explaining the comment of @user3159253. Your file1.config should

Running a shell script for a certain duration

I want to be able to run a script on Linux shell (bash) for a certain duration and sleep for a different duration. I’ve written something like the following snippet. However, I see only the sleep happening correctly but the execution stops after first execution. The response I get is ./script.sh: line 30: 1: not found. Maybe I’m missing something

Parsing parameters with zparseopts, but from within a sourced script

I have a zsh script myscr.zsh, which sources another script zparse.zsh, like this: zparse.zsh expects a variable number of parameters, which do NOT need to be parsed using zparseopt, but zparse.zsh should – among other things – parse the positional parameters passed to mysrc.zsh. This is tricky, since mysrc.zsh has its own copy of $, which is different from the

I’m getting errors in my shell script

MY CODE : THE ERRORS : Answer Your code has lots of issues. You were not consistent in your variable names (e.g. pp vs. PurPrice) You only use $ when you want the value of a variable (not on read’s for example). You can’t use strings with the integer test operators (-eq and so on). You need backticks to get

Bash Array Key from User Input

So I have a bash script which will scan a directory and run a function on a selected input. It seems that for some reason, the key is not setting from the array properly. What am I missing? All help is much appreciated! EDIT: As a side note, I can run the commands separately and get results. Here is the

Unable to write on /dev/* files

I’m writing a basic char device driver for Linux kernel. For this, the code flow I have considered is as follows: alloc_chrdev_region() -> to use dynamic allocation of major number class_create() -> to create device class in sysfs device_creat() -> to create device under /dev/ cdv_init() -> to initialize char device structure cdev_add() -> to add my device structure in

Using a glob expression passed as a bash script argument

TL;DR: Why isn’t invoking ./myscript foo* when myscript has var=$1 the same as invoking ./myscript with var=foo* hardcoded? Longer form I’ve come across a weird issue in a bash script I’m writing. I am sure there is a simple explanation, but I can’t figure it out. I am trying to pass a command line argument to be assigned as a

shell difference between redirect position

Is there any difference between these 2 lines? Because Robert told me that the first one only makes the I/O OP outside the for loop. But if I type tail -f /tmp/output.txt this is behaving exactly the same way. Answer They do the same if they succeed. However, there might be notable differences if they fail for whatever reason. The

Advertisement