Shell script not working in jenkins pipeline

Newbie to jenkins here. I am running jenkins 2.36.1 on centos 7 in single node mode.
I am trying to cd to a file and check if i have cd into it in bash script . but it does not seem to work

Here is snippet of my pipeline
ipeline {
agent any

 stages {
    stage('Untar') {
       steps {
          sh '''#!/bin/bash  
          sudo cd /lustre01/software/source/R 
           sudo pwd


The output shows the following
Running on [Jenkins]
[Pipeline] {
{ [Pipeline] stage
[Pipeline] { (Untar)
[Pipeline] sh


Am i missing something here with shell script. in jenkins pipeline


Sudo is essentially a sub shell, so it’ll change directory in that shell, exit, and go back to the default shell. So this won’t actually do anything

not sure what you are expecing to happen, but its printing the current workspace, if you are expected to be in a different directory, see above. (Which is why you should be clear what you are expecting to happen, vs what did happen)

In addition, I recommend you use dir step to change your directory, its a little more built in than the shell step

Thanks all
I got it working by using sudo and having
sh ‘’‘’